{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "1l8bWGmIJuQa"
   },
   "source": [
    "##### Copyright 2019 The TensorFlow Authors.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "cellView": "form",
    "execution": {
     "iopub.execute_input": "2023-11-07T23:17:50.885687Z",
     "iopub.status.busy": "2023-11-07T23:17:50.885428Z",
     "iopub.status.idle": "2023-11-07T23:17:50.889851Z",
     "shell.execute_reply": "2023-11-07T23:17:50.889169Z"
    },
    "id": "CPSnXS88KFEo"
   },
   "outputs": [],
   "source": [
    "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "# https://www.apache.org/licenses/LICENSE-2.0\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "89xNCIO5hiCj"
   },
   "source": [
    "# 使用分布策略保存和加载模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "A0lG6qgThxAS"
   },
   "source": [
    "## 概述\n",
    "\n",
    "本教程演示了如何在训练期间或训练之后使用 `tf.distribute.Strategy` 以 SavedModel 格式保存和加载模型。有两种用于保存和加载 Keras 模型的 API：高级（`tf.keras.Model.save` 和 `tf.keras.models.load_model`）和低级（`tf.saved_model.save` 和 `tf.saved_model.load`）。\n",
    "\n",
    "要全面了解 SavedModel 和序列化，请阅读[已保存模型指南](../../guide/saved_model.ipynb)和 [Keras 模型序列化指南](https://tensorflow.google.cn/guide/keras/save_and_serialize)。我们从一个简单的示例开始。\n",
    "\n",
    "小心：TensorFlow 模型是代码，对于不受信任的代码，一定要小心。请参阅[安全使用 TensorFlow](https://github.com/tensorflow/tensorflow/blob/master/SECURITY.md) 以了解详情。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "FITHltVKQ4eZ"
   },
   "source": [
    "导入依赖项："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:17:50.894020Z",
     "iopub.status.busy": "2023-11-07T23:17:50.893755Z",
     "iopub.status.idle": "2023-11-07T23:17:53.885686Z",
     "shell.execute_reply": "2023-11-07T23:17:53.884749Z"
    },
    "id": "RWG5HchAiOrZ"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:17:51.828961: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
      "2023-11-07 23:17:51.829033: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
      "2023-11-07 23:17:51.830761: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n"
     ]
    }
   ],
   "source": [
    "import tensorflow_datasets as tfds\n",
    "\n",
    "import tensorflow as tf\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qqapWj98ptNV"
   },
   "source": [
    "使用 TensorFlow Datasets 和 `tf.data` 加载和准备数据，并使用 `tf.distribute.MirroredStrategy` 创建模型："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:17:53.891591Z",
     "iopub.status.busy": "2023-11-07T23:17:53.890703Z",
     "iopub.status.idle": "2023-11-07T23:17:57.241860Z",
     "shell.execute_reply": "2023-11-07T23:17:57.241055Z"
    },
    "id": "yrYiAf_ziRyw"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    }
   ],
   "source": [
    "mirrored_strategy = tf.distribute.MirroredStrategy()\n",
    "\n",
    "def get_data():\n",
    "  datasets = tfds.load(name='mnist', as_supervised=True)\n",
    "  mnist_train, mnist_test = datasets['train'], datasets['test']\n",
    "\n",
    "  BUFFER_SIZE = 10000\n",
    "\n",
    "  BATCH_SIZE_PER_REPLICA = 64\n",
    "  BATCH_SIZE = BATCH_SIZE_PER_REPLICA * mirrored_strategy.num_replicas_in_sync\n",
    "\n",
    "  def scale(image, label):\n",
    "    image = tf.cast(image, tf.float32)\n",
    "    image /= 255\n",
    "\n",
    "    return image, label\n",
    "\n",
    "  train_dataset = mnist_train.map(scale).cache().shuffle(BUFFER_SIZE).batch(BATCH_SIZE)\n",
    "  eval_dataset = mnist_test.map(scale).batch(BATCH_SIZE)\n",
    "\n",
    "  return train_dataset, eval_dataset\n",
    "\n",
    "def get_model():\n",
    "  with mirrored_strategy.scope():\n",
    "    model = tf.keras.Sequential([\n",
    "        tf.keras.layers.Conv2D(32, 3, activation='relu', input_shape=(28, 28, 1)),\n",
    "        tf.keras.layers.MaxPooling2D(),\n",
    "        tf.keras.layers.Flatten(),\n",
    "        tf.keras.layers.Dense(64, activation='relu'),\n",
    "        tf.keras.layers.Dense(10)\n",
    "    ])\n",
    "\n",
    "    model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n",
    "                  optimizer=tf.keras.optimizers.Adam(),\n",
    "                  metrics=[tf.metrics.SparseCategoricalAccuracy()])\n",
    "    return model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qmU4Y3feS9Na"
   },
   "source": [
    "使用 `tf.keras.Model.fit` 训练模型： "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:17:57.246285Z",
     "iopub.status.busy": "2023-11-07T23:17:57.245999Z",
     "iopub.status.idle": "2023-11-07T23:18:09.747444Z",
     "shell.execute_reply": "2023-11-07T23:18:09.746681Z"
    },
    "id": "zmGurbJmS_vN"
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:17:58.325808: W tensorflow/core/grappler/optimizers/data/auto_shard.cc:553] The `assert_cardinality` transformation is currently not handled by the auto-shard rewrite and will be removed.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
      "I0000 00:00:1699399085.009935  522218 device_compiler.h:186] Compiled cluster using XLA!  This line is logged at most once for the lifetime of the process.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 26:27 - loss: 2.3098 - sparse_categorical_accuracy: 0.1016"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "  7/235 [..............................] - ETA: 2s - loss: 1.8855 - sparse_categorical_accuracy: 0.4805   "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 14/235 [>.............................] - ETA: 1s - loss: 1.4637 - sparse_categorical_accuracy: 0.6303"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 20/235 [=>............................] - ETA: 1s - loss: 1.2098 - sparse_categorical_accuracy: 0.6912"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 26/235 [==>...........................] - ETA: 1s - loss: 1.0419 - sparse_categorical_accuracy: 0.7300"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 33/235 [===>..........................] - ETA: 1s - loss: 0.9096 - sparse_categorical_accuracy: 0.7627"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 39/235 [===>..........................] - ETA: 1s - loss: 0.8239 - sparse_categorical_accuracy: 0.7827"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 45/235 [====>.........................] - ETA: 1s - loss: 0.7641 - sparse_categorical_accuracy: 0.7958"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 52/235 [=====>........................] - ETA: 1s - loss: 0.7112 - sparse_categorical_accuracy: 0.8082"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 59/235 [======>.......................] - ETA: 1s - loss: 0.6632 - sparse_categorical_accuracy: 0.8191"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 65/235 [=======>......................] - ETA: 1s - loss: 0.6312 - sparse_categorical_accuracy: 0.8273"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 72/235 [========>.....................] - ETA: 1s - loss: 0.5960 - sparse_categorical_accuracy: 0.8359"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 79/235 [=========>....................] - ETA: 1s - loss: 0.5650 - sparse_categorical_accuracy: 0.8439"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 86/235 [=========>....................] - ETA: 1s - loss: 0.5401 - sparse_categorical_accuracy: 0.8499"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 92/235 [==========>...................] - ETA: 1s - loss: 0.5208 - sparse_categorical_accuracy: 0.8547"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 98/235 [===========>..................] - ETA: 1s - loss: 0.5031 - sparse_categorical_accuracy: 0.8596"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "105/235 [============>.................] - ETA: 1s - loss: 0.4849 - sparse_categorical_accuracy: 0.8642"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "112/235 [=============>................] - ETA: 1s - loss: 0.4695 - sparse_categorical_accuracy: 0.8680"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "118/235 [==============>...............] - ETA: 0s - loss: 0.4566 - sparse_categorical_accuracy: 0.8715"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "125/235 [==============>...............] - ETA: 0s - loss: 0.4436 - sparse_categorical_accuracy: 0.8749"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "132/235 [===============>..............] - ETA: 0s - loss: 0.4306 - sparse_categorical_accuracy: 0.8783"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "139/235 [================>.............] - ETA: 0s - loss: 0.4196 - sparse_categorical_accuracy: 0.8815"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "146/235 [=================>............] - ETA: 0s - loss: 0.4098 - sparse_categorical_accuracy: 0.8841"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "153/235 [==================>...........] - ETA: 0s - loss: 0.4011 - sparse_categorical_accuracy: 0.8862"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "160/235 [===================>..........] - ETA: 0s - loss: 0.3913 - sparse_categorical_accuracy: 0.8888"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "167/235 [====================>.........] - ETA: 0s - loss: 0.3834 - sparse_categorical_accuracy: 0.8910"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "174/235 [=====================>........] - ETA: 0s - loss: 0.3762 - sparse_categorical_accuracy: 0.8930"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "181/235 [======================>.......] - ETA: 0s - loss: 0.3674 - sparse_categorical_accuracy: 0.8957"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "188/235 [=======================>......] - ETA: 0s - loss: 0.3588 - sparse_categorical_accuracy: 0.8980"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "195/235 [=======================>......] - ETA: 0s - loss: 0.3513 - sparse_categorical_accuracy: 0.9002"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "203/235 [========================>.....] - ETA: 0s - loss: 0.3432 - sparse_categorical_accuracy: 0.9025"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "211/235 [=========================>....] - ETA: 0s - loss: 0.3366 - sparse_categorical_accuracy: 0.9044"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "218/235 [==========================>...] - ETA: 0s - loss: 0.3302 - sparse_categorical_accuracy: 0.9062"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "225/235 [===========================>..] - ETA: 0s - loss: 0.3240 - sparse_categorical_accuracy: 0.9081"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "232/235 [============================>.] - ETA: 0s - loss: 0.3185 - sparse_categorical_accuracy: 0.9097"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - ETA: 0s - loss: 0.3166 - sparse_categorical_accuracy: 0.9101"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 9s 9ms/step - loss: 0.3166 - sparse_categorical_accuracy: 0.9101\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 2/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 9s - loss: 0.1225 - sparse_categorical_accuracy: 0.9766"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "  8/235 [>.............................] - ETA: 1s - loss: 0.1251 - sparse_categorical_accuracy: 0.9688"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 15/235 [>.............................] - ETA: 1s - loss: 0.1288 - sparse_categorical_accuracy: 0.9651"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 23/235 [=>............................] - ETA: 1s - loss: 0.1264 - sparse_categorical_accuracy: 0.9660"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 30/235 [==>...........................] - ETA: 1s - loss: 0.1247 - sparse_categorical_accuracy: 0.9658"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 38/235 [===>..........................] - ETA: 1s - loss: 0.1215 - sparse_categorical_accuracy: 0.9655"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 46/235 [====>.........................] - ETA: 1s - loss: 0.1195 - sparse_categorical_accuracy: 0.9657"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 54/235 [=====>........................] - ETA: 1s - loss: 0.1155 - sparse_categorical_accuracy: 0.9669"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 61/235 [======>.......................] - ETA: 1s - loss: 0.1135 - sparse_categorical_accuracy: 0.9670"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 69/235 [=======>......................] - ETA: 1s - loss: 0.1107 - sparse_categorical_accuracy: 0.9677"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 77/235 [========>.....................] - ETA: 1s - loss: 0.1088 - sparse_categorical_accuracy: 0.9684"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 85/235 [=========>....................] - ETA: 1s - loss: 0.1105 - sparse_categorical_accuracy: 0.9684"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 93/235 [==========>...................] - ETA: 1s - loss: 0.1100 - sparse_categorical_accuracy: 0.9685"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "101/235 [===========>..................] - ETA: 0s - loss: 0.1100 - sparse_categorical_accuracy: 0.9685"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "109/235 [============>.................] - ETA: 0s - loss: 0.1083 - sparse_categorical_accuracy: 0.9687"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "117/235 [=============>................] - ETA: 0s - loss: 0.1073 - sparse_categorical_accuracy: 0.9692"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "125/235 [==============>...............] - ETA: 0s - loss: 0.1058 - sparse_categorical_accuracy: 0.9696"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "132/235 [===============>..............] - ETA: 0s - loss: 0.1052 - sparse_categorical_accuracy: 0.9696"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "139/235 [================>.............] - ETA: 0s - loss: 0.1044 - sparse_categorical_accuracy: 0.9697"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "146/235 [=================>............] - ETA: 0s - loss: 0.1039 - sparse_categorical_accuracy: 0.9699"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "153/235 [==================>...........] - ETA: 0s - loss: 0.1039 - sparse_categorical_accuracy: 0.9700"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "160/235 [===================>..........] - ETA: 0s - loss: 0.1035 - sparse_categorical_accuracy: 0.9699"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "167/235 [====================>.........] - ETA: 0s - loss: 0.1034 - sparse_categorical_accuracy: 0.9701"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "175/235 [=====================>........] - ETA: 0s - loss: 0.1029 - sparse_categorical_accuracy: 0.9703"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "182/235 [======================>.......] - ETA: 0s - loss: 0.1023 - sparse_categorical_accuracy: 0.9704"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "190/235 [=======================>......] - ETA: 0s - loss: 0.1012 - sparse_categorical_accuracy: 0.9707"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "198/235 [========================>.....] - ETA: 0s - loss: 0.1005 - sparse_categorical_accuracy: 0.9707"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "205/235 [=========================>....] - ETA: 0s - loss: 0.0996 - sparse_categorical_accuracy: 0.9711"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "212/235 [==========================>...] - ETA: 0s - loss: 0.0989 - sparse_categorical_accuracy: 0.9714"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "220/235 [===========================>..] - ETA: 0s - loss: 0.0982 - sparse_categorical_accuracy: 0.9718"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "228/235 [============================>.] - ETA: 0s - loss: 0.0975 - sparse_categorical_accuracy: 0.9721"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - ETA: 0s - loss: 0.0970 - sparse_categorical_accuracy: 0.9722"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 2s 7ms/step - loss: 0.0970 - sparse_categorical_accuracy: 0.9722\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.src.callbacks.History at 0x7f7a0c273700>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = get_model()\n",
    "train_dataset, eval_dataset = get_data()\n",
    "model.fit(train_dataset, epochs=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "L01wjgvRizHS"
   },
   "source": [
    "## 保存和加载模型\n",
    "\n",
    "现在，您已经有一个简单的模型可供使用，让我们探索保存/加载 API。有两种可用的 API：\n",
    "\n",
    "- 高级 (Keras)：`Model.save` 和 `tf.keras.models.load_model`（`.keras` zip 存档格式）\n",
    "- 低级：`tf.saved_model.save` 和 `tf.saved_model.load`（TF SavedModel 格式）\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "FX_IF2F1tvFs"
   },
   "source": [
    "### Keras API"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "O8xfceg4Z3H_"
   },
   "source": [
    "以下为使用 Keras API 保存和加载模型的示例："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:09.751572Z",
     "iopub.status.busy": "2023-11-07T23:18:09.750939Z",
     "iopub.status.idle": "2023-11-07T23:18:09.815772Z",
     "shell.execute_reply": "2023-11-07T23:18:09.814930Z"
    },
    "id": "LYOStjV5knTQ"
   },
   "outputs": [],
   "source": [
    "keras_model_path = '/tmp/keras_save.keras'\n",
    "model.save(keras_model_path)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "yvQIdQp3zNMp"
   },
   "source": [
    "恢复无 `tf.distribute.Strategy` 的模型："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:09.819871Z",
     "iopub.status.busy": "2023-11-07T23:18:09.819567Z",
     "iopub.status.idle": "2023-11-07T23:18:13.047358Z",
     "shell.execute_reply": "2023-11-07T23:18:13.046681Z"
    },
    "id": "WrXAAVtrzRgv"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 3:57 - loss: 0.0419 - sparse_categorical_accuracy: 0.9883"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 12/235 [>.............................] - ETA: 1s - loss: 0.0697 - sparse_categorical_accuracy: 0.9808  "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 23/235 [=>............................] - ETA: 1s - loss: 0.0730 - sparse_categorical_accuracy: 0.9808"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 34/235 [===>..........................] - ETA: 0s - loss: 0.0757 - sparse_categorical_accuracy: 0.9792"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 45/235 [====>.........................] - ETA: 0s - loss: 0.0738 - sparse_categorical_accuracy: 0.9793"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 57/235 [======>.......................] - ETA: 0s - loss: 0.0692 - sparse_categorical_accuracy: 0.9806"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 69/235 [=======>......................] - ETA: 0s - loss: 0.0690 - sparse_categorical_accuracy: 0.9806"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 81/235 [=========>....................] - ETA: 0s - loss: 0.0680 - sparse_categorical_accuracy: 0.9808"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 93/235 [==========>...................] - ETA: 0s - loss: 0.0679 - sparse_categorical_accuracy: 0.9804"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "106/235 [============>.................] - ETA: 0s - loss: 0.0681 - sparse_categorical_accuracy: 0.9803"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "119/235 [==============>...............] - ETA: 0s - loss: 0.0681 - sparse_categorical_accuracy: 0.9804"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "132/235 [===============>..............] - ETA: 0s - loss: 0.0673 - sparse_categorical_accuracy: 0.9806"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "145/235 [=================>............] - ETA: 0s - loss: 0.0661 - sparse_categorical_accuracy: 0.9811"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "158/235 [===================>..........] - ETA: 0s - loss: 0.0660 - sparse_categorical_accuracy: 0.9811"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "171/235 [====================>.........] - ETA: 0s - loss: 0.0656 - sparse_categorical_accuracy: 0.9813"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "184/235 [======================>.......] - ETA: 0s - loss: 0.0652 - sparse_categorical_accuracy: 0.9815"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "197/235 [========================>.....] - ETA: 0s - loss: 0.0652 - sparse_categorical_accuracy: 0.9814"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "210/235 [=========================>....] - ETA: 0s - loss: 0.0647 - sparse_categorical_accuracy: 0.9816"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "223/235 [===========================>..] - ETA: 0s - loss: 0.0648 - sparse_categorical_accuracy: 0.9815"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - ETA: 0s - loss: 0.0644 - sparse_categorical_accuracy: 0.9817"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 2s 5ms/step - loss: 0.0644 - sparse_categorical_accuracy: 0.9817\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 2/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 7s - loss: 0.0286 - sparse_categorical_accuracy: 0.9961"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 14/235 [>.............................] - ETA: 0s - loss: 0.0594 - sparse_categorical_accuracy: 0.9819"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 27/235 [==>...........................] - ETA: 0s - loss: 0.0567 - sparse_categorical_accuracy: 0.9828"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 40/235 [====>.........................] - ETA: 0s - loss: 0.0566 - sparse_categorical_accuracy: 0.9823"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 53/235 [=====>........................] - ETA: 0s - loss: 0.0536 - sparse_categorical_accuracy: 0.9838"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 66/235 [=======>......................] - ETA: 0s - loss: 0.0550 - sparse_categorical_accuracy: 0.9840"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 79/235 [=========>....................] - ETA: 0s - loss: 0.0557 - sparse_categorical_accuracy: 0.9839"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 92/235 [==========>...................] - ETA: 0s - loss: 0.0547 - sparse_categorical_accuracy: 0.9840"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "105/235 [============>.................] - ETA: 0s - loss: 0.0537 - sparse_categorical_accuracy: 0.9845"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "118/235 [==============>...............] - ETA: 0s - loss: 0.0527 - sparse_categorical_accuracy: 0.9849"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "131/235 [===============>..............] - ETA: 0s - loss: 0.0523 - sparse_categorical_accuracy: 0.9851"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "144/235 [=================>............] - ETA: 0s - loss: 0.0523 - sparse_categorical_accuracy: 0.9848"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "158/235 [===================>..........] - ETA: 0s - loss: 0.0514 - sparse_categorical_accuracy: 0.9850"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "171/235 [====================>.........] - ETA: 0s - loss: 0.0520 - sparse_categorical_accuracy: 0.9846"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "185/235 [======================>.......] - ETA: 0s - loss: 0.0514 - sparse_categorical_accuracy: 0.9848"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "199/235 [========================>.....] - ETA: 0s - loss: 0.0512 - sparse_categorical_accuracy: 0.9847"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "212/235 [==========================>...] - ETA: 0s - loss: 0.0505 - sparse_categorical_accuracy: 0.9850"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "225/235 [===========================>..] - ETA: 0s - loss: 0.0506 - sparse_categorical_accuracy: 0.9851"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 1s 4ms/step - loss: 0.0506 - sparse_categorical_accuracy: 0.9851\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<keras.src.callbacks.History at 0x7f7a6b052490>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "restored_keras_model = tf.keras.models.load_model(keras_model_path)\n",
    "restored_keras_model.fit(train_dataset, epochs=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "gYAnskzorda-"
   },
   "source": [
    "恢复模型后，您可以继在它上面续训练，甚至不需要再次调用 `Model.compile`，因为它在保存之前已经编译。模型以 Keras zip 存档格式保存，由 `.keras` 扩展名标记。有关详情，请参阅 [Keras 保存指南](https://tensorflow.google.cn/guide/keras/save_and_serialize)。\n",
    "\n",
    "现在，恢复模型并使用 `tf.distribute.Strategy` 对其进行训练："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:13.051432Z",
     "iopub.status.busy": "2023-11-07T23:18:13.050705Z",
     "iopub.status.idle": "2023-11-07T23:18:19.538561Z",
     "shell.execute_reply": "2023-11-07T23:18:19.537708Z"
    },
    "id": "wROPrJaAqBQz"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/2\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:18:13.264179: W tensorflow/core/grappler/optimizers/data/auto_shard.cc:553] The `assert_cardinality` transformation is currently not handled by the auto-shard rewrite and will be removed.\n",
      "2023-11-07 23:18:13.328327: W tensorflow/core/framework/dataset.cc:959] Input of GeneratorDatasetOp::Dataset will not be optimized because the dataset does not implement the AsGraphDefInternal() method needed to apply optimizations.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 2:05 - loss: 0.0732 - sparse_categorical_accuracy: 0.9844"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "  5/235 [..............................] - ETA: 2s - loss: 0.0701 - sparse_categorical_accuracy: 0.9852  "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 10/235 [>.............................] - ETA: 2s - loss: 0.0726 - sparse_categorical_accuracy: 0.9793"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 15/235 [>.............................] - ETA: 2s - loss: 0.0740 - sparse_categorical_accuracy: 0.9812"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:18:13.954467: E external/local_xla/xla/stream_executor/stream_executor_internal.h:177] SetPriority unimplemented for this stream.\n",
      "2023-11-07 23:18:13.988420: E external/local_xla/xla/stream_executor/stream_executor_internal.h:177] SetPriority unimplemented for this stream.\n",
      "2023-11-07 23:18:14.002096: E external/local_xla/xla/stream_executor/stream_executor_internal.h:177] SetPriority unimplemented for this stream.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 20/235 [=>............................] - ETA: 2s - loss: 0.0744 - sparse_categorical_accuracy: 0.9795"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 25/235 [==>...........................] - ETA: 2s - loss: 0.0766 - sparse_categorical_accuracy: 0.9787"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 29/235 [==>...........................] - ETA: 2s - loss: 0.0751 - sparse_categorical_accuracy: 0.9795"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 34/235 [===>..........................] - ETA: 2s - loss: 0.0763 - sparse_categorical_accuracy: 0.9790"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 39/235 [===>..........................] - ETA: 2s - loss: 0.0762 - sparse_categorical_accuracy: 0.9789"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 43/235 [====>.........................] - ETA: 2s - loss: 0.0743 - sparse_categorical_accuracy: 0.9793"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 48/235 [=====>........................] - ETA: 2s - loss: 0.0725 - sparse_categorical_accuracy: 0.9799"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 52/235 [=====>........................] - ETA: 2s - loss: 0.0704 - sparse_categorical_accuracy: 0.9803"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 56/235 [======>.......................] - ETA: 2s - loss: 0.0691 - sparse_categorical_accuracy: 0.9806"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 61/235 [======>.......................] - ETA: 2s - loss: 0.0690 - sparse_categorical_accuracy: 0.9807"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 65/235 [=======>......................] - ETA: 2s - loss: 0.0700 - sparse_categorical_accuracy: 0.9803"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 70/235 [=======>......................] - ETA: 1s - loss: 0.0720 - sparse_categorical_accuracy: 0.9797"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 75/235 [========>.....................] - ETA: 1s - loss: 0.0717 - sparse_categorical_accuracy: 0.9796"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 80/235 [=========>....................] - ETA: 1s - loss: 0.0720 - sparse_categorical_accuracy: 0.9797"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 84/235 [=========>....................] - ETA: 1s - loss: 0.0713 - sparse_categorical_accuracy: 0.9800"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 89/235 [==========>...................] - ETA: 1s - loss: 0.0717 - sparse_categorical_accuracy: 0.9798"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 94/235 [===========>..................] - ETA: 1s - loss: 0.0713 - sparse_categorical_accuracy: 0.9798"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 99/235 [===========>..................] - ETA: 1s - loss: 0.0715 - sparse_categorical_accuracy: 0.9798"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "104/235 [============>.................] - ETA: 1s - loss: 0.0709 - sparse_categorical_accuracy: 0.9799"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "109/235 [============>.................] - ETA: 1s - loss: 0.0707 - sparse_categorical_accuracy: 0.9801"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "114/235 [=============>................] - ETA: 1s - loss: 0.0703 - sparse_categorical_accuracy: 0.9800"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "119/235 [==============>...............] - ETA: 1s - loss: 0.0702 - sparse_categorical_accuracy: 0.9799"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "124/235 [==============>...............] - ETA: 1s - loss: 0.0702 - sparse_categorical_accuracy: 0.9799"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "129/235 [===============>..............] - ETA: 1s - loss: 0.0705 - sparse_categorical_accuracy: 0.9798"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "134/235 [================>.............] - ETA: 1s - loss: 0.0704 - sparse_categorical_accuracy: 0.9798"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "139/235 [================>.............] - ETA: 1s - loss: 0.0702 - sparse_categorical_accuracy: 0.9799"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "144/235 [=================>............] - ETA: 1s - loss: 0.0697 - sparse_categorical_accuracy: 0.9801"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "149/235 [==================>...........] - ETA: 1s - loss: 0.0693 - sparse_categorical_accuracy: 0.9800"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "154/235 [==================>...........] - ETA: 0s - loss: 0.0687 - sparse_categorical_accuracy: 0.9802"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "159/235 [===================>..........] - ETA: 0s - loss: 0.0684 - sparse_categorical_accuracy: 0.9803"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "164/235 [===================>..........] - ETA: 0s - loss: 0.0679 - sparse_categorical_accuracy: 0.9804"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "169/235 [====================>.........] - ETA: 0s - loss: 0.0675 - sparse_categorical_accuracy: 0.9805"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "174/235 [=====================>........] - ETA: 0s - loss: 0.0671 - sparse_categorical_accuracy: 0.9807"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "179/235 [=====================>........] - ETA: 0s - loss: 0.0669 - sparse_categorical_accuracy: 0.9806"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "184/235 [======================>.......] - ETA: 0s - loss: 0.0665 - sparse_categorical_accuracy: 0.9808"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "189/235 [=======================>......] - ETA: 0s - loss: 0.0661 - sparse_categorical_accuracy: 0.9808"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "194/235 [=======================>......] - ETA: 0s - loss: 0.0662 - sparse_categorical_accuracy: 0.9808"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "199/235 [========================>.....] - ETA: 0s - loss: 0.0662 - sparse_categorical_accuracy: 0.9808"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "204/235 [=========================>....] - ETA: 0s - loss: 0.0658 - sparse_categorical_accuracy: 0.9810"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "209/235 [=========================>....] - ETA: 0s - loss: 0.0659 - sparse_categorical_accuracy: 0.9810"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "214/235 [==========================>...] - ETA: 0s - loss: 0.0657 - sparse_categorical_accuracy: 0.9810"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "219/235 [==========================>...] - ETA: 0s - loss: 0.0655 - sparse_categorical_accuracy: 0.9811"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "224/235 [===========================>..] - ETA: 0s - loss: 0.0655 - sparse_categorical_accuracy: 0.9811"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "229/235 [============================>.] - ETA: 0s - loss: 0.0654 - sparse_categorical_accuracy: 0.9811"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "234/235 [============================>.] - ETA: 0s - loss: 0.0651 - sparse_categorical_accuracy: 0.9812"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 3s 12ms/step - loss: 0.0652 - sparse_categorical_accuracy: 0.9811\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 2/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 10s - loss: 0.0766 - sparse_categorical_accuracy: 0.9727"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "  5/235 [..............................] - ETA: 3s - loss: 0.0519 - sparse_categorical_accuracy: 0.9828 "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 10/235 [>.............................] - ETA: 2s - loss: 0.0627 - sparse_categorical_accuracy: 0.9816"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 15/235 [>.............................] - ETA: 2s - loss: 0.0659 - sparse_categorical_accuracy: 0.9810"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 20/235 [=>............................] - ETA: 2s - loss: 0.0625 - sparse_categorical_accuracy: 0.9814"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 24/235 [==>...........................] - ETA: 2s - loss: 0.0604 - sparse_categorical_accuracy: 0.9818"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 29/235 [==>...........................] - ETA: 2s - loss: 0.0583 - sparse_categorical_accuracy: 0.9824"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 34/235 [===>..........................] - ETA: 2s - loss: 0.0578 - sparse_categorical_accuracy: 0.9823"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 39/235 [===>..........................] - ETA: 2s - loss: 0.0568 - sparse_categorical_accuracy: 0.9824"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 44/235 [====>.........................] - ETA: 2s - loss: 0.0563 - sparse_categorical_accuracy: 0.9826"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 49/235 [=====>........................] - ETA: 2s - loss: 0.0570 - sparse_categorical_accuracy: 0.9833"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 54/235 [=====>........................] - ETA: 2s - loss: 0.0566 - sparse_categorical_accuracy: 0.9835"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 59/235 [======>.......................] - ETA: 2s - loss: 0.0566 - sparse_categorical_accuracy: 0.9833"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 63/235 [=======>......................] - ETA: 1s - loss: 0.0552 - sparse_categorical_accuracy: 0.9837"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 68/235 [=======>......................] - ETA: 1s - loss: 0.0545 - sparse_categorical_accuracy: 0.9841"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 73/235 [========>.....................] - ETA: 1s - loss: 0.0541 - sparse_categorical_accuracy: 0.9843"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 78/235 [========>.....................] - ETA: 1s - loss: 0.0542 - sparse_categorical_accuracy: 0.9843"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 83/235 [=========>....................] - ETA: 1s - loss: 0.0533 - sparse_categorical_accuracy: 0.9845"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 88/235 [==========>...................] - ETA: 1s - loss: 0.0536 - sparse_categorical_accuracy: 0.9845"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 93/235 [==========>...................] - ETA: 1s - loss: 0.0539 - sparse_categorical_accuracy: 0.9843"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 98/235 [===========>..................] - ETA: 1s - loss: 0.0529 - sparse_categorical_accuracy: 0.9846"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "103/235 [============>.................] - ETA: 1s - loss: 0.0531 - sparse_categorical_accuracy: 0.9845"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "108/235 [============>.................] - ETA: 1s - loss: 0.0528 - sparse_categorical_accuracy: 0.9846"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "113/235 [=============>................] - ETA: 1s - loss: 0.0528 - sparse_categorical_accuracy: 0.9845"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "117/235 [=============>................] - ETA: 1s - loss: 0.0524 - sparse_categorical_accuracy: 0.9846"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "122/235 [==============>...............] - ETA: 1s - loss: 0.0524 - sparse_categorical_accuracy: 0.9847"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "127/235 [===============>..............] - ETA: 1s - loss: 0.0524 - sparse_categorical_accuracy: 0.9848"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "132/235 [===============>..............] - ETA: 1s - loss: 0.0521 - sparse_categorical_accuracy: 0.9850"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "137/235 [================>.............] - ETA: 1s - loss: 0.0525 - sparse_categorical_accuracy: 0.9848"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "142/235 [=================>............] - ETA: 1s - loss: 0.0521 - sparse_categorical_accuracy: 0.9850"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "147/235 [=================>............] - ETA: 1s - loss: 0.0520 - sparse_categorical_accuracy: 0.9849"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "152/235 [==================>...........] - ETA: 0s - loss: 0.0520 - sparse_categorical_accuracy: 0.9849"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "156/235 [==================>...........] - ETA: 0s - loss: 0.0521 - sparse_categorical_accuracy: 0.9849"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "161/235 [===================>..........] - ETA: 0s - loss: 0.0520 - sparse_categorical_accuracy: 0.9849"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "166/235 [====================>.........] - ETA: 0s - loss: 0.0520 - sparse_categorical_accuracy: 0.9850"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "171/235 [====================>.........] - ETA: 0s - loss: 0.0526 - sparse_categorical_accuracy: 0.9848"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "176/235 [=====================>........] - ETA: 0s - loss: 0.0533 - sparse_categorical_accuracy: 0.9846"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "181/235 [======================>.......] - ETA: 0s - loss: 0.0531 - sparse_categorical_accuracy: 0.9847"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "186/235 [======================>.......] - ETA: 0s - loss: 0.0528 - sparse_categorical_accuracy: 0.9848"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "191/235 [=======================>......] - ETA: 0s - loss: 0.0529 - sparse_categorical_accuracy: 0.9847"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "196/235 [========================>.....] - ETA: 0s - loss: 0.0526 - sparse_categorical_accuracy: 0.9848"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "201/235 [========================>.....] - ETA: 0s - loss: 0.0523 - sparse_categorical_accuracy: 0.9849"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "206/235 [=========================>....] - ETA: 0s - loss: 0.0519 - sparse_categorical_accuracy: 0.9850"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "211/235 [=========================>....] - ETA: 0s - loss: 0.0516 - sparse_categorical_accuracy: 0.9851"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "216/235 [==========================>...] - ETA: 0s - loss: 0.0511 - sparse_categorical_accuracy: 0.9852"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "221/235 [===========================>..] - ETA: 0s - loss: 0.0514 - sparse_categorical_accuracy: 0.9852"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "226/235 [===========================>..] - ETA: 0s - loss: 0.0513 - sparse_categorical_accuracy: 0.9851"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "231/235 [============================>.] - ETA: 0s - loss: 0.0509 - sparse_categorical_accuracy: 0.9852"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 3s 11ms/step - loss: 0.0510 - sparse_categorical_accuracy: 0.9851\n"
     ]
    }
   ],
   "source": [
    "another_strategy = tf.distribute.OneDeviceStrategy('/cpu:0')\n",
    "with another_strategy.scope():\n",
    "  restored_keras_model_ds = tf.keras.models.load_model(keras_model_path)\n",
    "  restored_keras_model_ds.fit(train_dataset, epochs=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "PdiiPmL5tQk5"
   },
   "source": [
    "正如 `Model.fit` 输出所示，`tf.distribute.Strategy` 可以按预期进行加载。此处使用的策略不必与保存前所用策略相同。 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "3CrXIbmFt0f6"
   },
   "source": [
    "### `tf.saved_model` API"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "HtGzPp6et4Em"
   },
   "source": [
    "使用较低级别的 API 保存模型类似于 Keras API："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:19.543346Z",
     "iopub.status.busy": "2023-11-07T23:18:19.542796Z",
     "iopub.status.idle": "2023-11-07T23:18:20.149791Z",
     "shell.execute_reply": "2023-11-07T23:18:20.149051Z"
    },
    "id": "4y6T31APuCqK"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    }
   ],
   "source": [
    "model = get_model()  # get a fresh model\n",
    "saved_model_path = '/tmp/tf_save'\n",
    "tf.saved_model.save(model, saved_model_path)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "q1QNRYcwuRll"
   },
   "source": [
    "可以使用 `tf.saved_model.load` 进行加载。但是，由于它是一个较低级别的 API（因此用例范围更广泛），不会返回 Keras 模型。相反，它会返回一个对象，其中包含可用于进行推断的函数。例如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:20.154501Z",
     "iopub.status.busy": "2023-11-07T23:18:20.154180Z",
     "iopub.status.idle": "2023-11-07T23:18:20.291148Z",
     "shell.execute_reply": "2023-11-07T23:18:20.290050Z"
    },
    "id": "aaEKqBSPwAuM"
   },
   "outputs": [],
   "source": [
    "DEFAULT_FUNCTION_KEY = 'serving_default'\n",
    "loaded = tf.saved_model.load(saved_model_path)\n",
    "inference_func = loaded.signatures[DEFAULT_FUNCTION_KEY]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "x65l7AaHUZCA"
   },
   "source": [
    "加载的对象可能包含多个函数，每个函数与一个键关联。`\"serving_default\"` 键是使用已保存的 Keras 模型的推断函数的默认键。要使用此函数进行推断，请运行以下代码： "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:20.295341Z",
     "iopub.status.busy": "2023-11-07T23:18:20.295068Z",
     "iopub.status.idle": "2023-11-07T23:18:20.557318Z",
     "shell.execute_reply": "2023-11-07T23:18:20.556452Z"
    },
    "id": "5Ore5q8-UjW1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'dense_3': <tf.Tensor: shape=(256, 10), dtype=float32, numpy=\n",
      "array([[ 0.1147381 , -0.40301684,  0.04525661, ..., -0.00361927,\n",
      "        -0.16612433, -0.0153662 ],\n",
      "       [ 0.23993656, -0.2951342 ,  0.11567082, ..., -0.018293  ,\n",
      "        -0.25642908, -0.12756145],\n",
      "       [ 0.12482558, -0.1498732 , -0.02880868, ...,  0.10482813,\n",
      "        -0.04954109,  0.03868026],\n",
      "       ...,\n",
      "       [ 0.24344432, -0.15270862,  0.07865744, ...,  0.07004395,\n",
      "        -0.13115454, -0.06379548],\n",
      "       [ 0.18582651, -0.06589739,  0.0035552 , ...,  0.05252723,\n",
      "        -0.15672804, -0.01999891],\n",
      "       [ 0.10272254, -0.19479191,  0.0195781 , ..., -0.00804898,\n",
      "        -0.19664931, -0.12797697]], dtype=float32)>}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:18:20.522652: W tensorflow/core/kernels/data/cache_dataset_ops.cc:858] The calling iterator did not fully read the dataset being cached. In order to avoid unexpected truncation of the dataset, the partially cached contents of the dataset  will be discarded. This can happen if you have an input pipeline similar to `dataset.cache().take(k).repeat()`. You should use `dataset.take(k).cache().repeat()` instead.\n"
     ]
    }
   ],
   "source": [
    "predict_dataset = eval_dataset.map(lambda image, label: image)\n",
    "for batch in predict_dataset.take(1):\n",
    "  print(inference_func(batch))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "osB1LY8WwUJZ"
   },
   "source": [
    "您还可以采用分布式方式加载和进行推断："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:20.561235Z",
     "iopub.status.busy": "2023-11-07T23:18:20.560943Z",
     "iopub.status.idle": "2023-11-07T23:18:21.498621Z",
     "shell.execute_reply": "2023-11-07T23:18:21.497813Z"
    },
    "id": "iDYvu12zYTmT"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:18:20.756679: W tensorflow/core/grappler/optimizers/data/auto_shard.cc:553] The `assert_cardinality` transformation is currently not handled by the auto-shard rewrite and will be removed.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Using MirroredStrategy eagerly has significant overhead currently. We will be working on improving this in the future, but for now please wrap `call_for_each_replica` or `experimental_run` or `run` inside a tf.function to get the best performance.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Using MirroredStrategy eagerly has significant overhead currently. We will be working on improving this in the future, but for now please wrap `call_for_each_replica` or `experimental_run` or `run` inside a tf.function to get the best performance.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'dense_3': PerReplica:{\n",
      "  0: <tf.Tensor: shape=(64, 10), dtype=float32, numpy=\n",
      "array([[ 1.14738092e-01, -4.03016806e-01,  4.52566147e-02,\n",
      "         4.16727774e-02, -1.74182177e-01, -1.42247193e-02,\n",
      "         1.34800702e-01, -3.61925364e-03, -1.66124314e-01,\n",
      "        -1.53662562e-02],\n",
      "       [ 2.39936545e-01, -2.95134246e-01,  1.15670875e-01,\n",
      "         6.21562228e-02, -5.74412942e-03,  9.67399850e-02,\n",
      "         6.38412088e-02, -1.82929561e-02, -2.56429106e-01,\n",
      "        -1.27561510e-01],\n",
      "       [ 1.24825627e-01, -1.49873167e-01, -2.88086776e-02,\n",
      "         5.14284968e-02, -1.49795488e-01,  5.63685335e-02,\n",
      "        -1.25008225e-02,  1.04828164e-01, -4.95411083e-02,\n",
      "         3.86802554e-02],\n",
      "       [-3.14452238e-02, -1.13862000e-01,  3.59135307e-02,\n",
      "         3.37418914e-03, -9.56010595e-02,  8.71438980e-02,\n",
      "         3.11656222e-02, -8.25512223e-03, -2.66045481e-02,\n",
      "         4.20068875e-02],\n",
      "       [ 3.10148541e-02, -1.27727151e-01,  2.81632431e-02,\n",
      "         1.84415001e-02, -5.98692782e-02,  3.23428214e-02,\n",
      "         1.68298408e-02,  1.26852781e-01, -2.95518860e-02,\n",
      "         5.77915385e-02],\n",
      "       [ 2.76307046e-01, -3.25123250e-01,  4.44254279e-02,\n",
      "        -3.92483473e-02, -1.58822447e-01, -1.81119330e-02,\n",
      "         1.93657145e-01, -1.59449875e-03, -1.98606268e-01,\n",
      "        -1.35647625e-01],\n",
      "       [ 2.55708933e-01, -2.18255267e-01,  1.28493115e-01,\n",
      "        -4.39336300e-02, -1.41243652e-01,  8.09284598e-02,\n",
      "         1.08400889e-01,  1.75348297e-01, -7.91441277e-02,\n",
      "        -8.59785229e-02],\n",
      "       [ 5.21239787e-02, -1.76998034e-01, -2.13304833e-02,\n",
      "        -7.83970486e-03, -5.99634312e-02, -3.24056335e-02,\n",
      "         1.27930865e-01,  1.46872252e-02, -9.80568081e-02,\n",
      "        -7.00330585e-02],\n",
      "       [ 2.82409132e-01, -1.93280309e-01, -8.35070014e-03,\n",
      "         4.52031568e-02, -7.35079646e-02,  7.34596774e-02,\n",
      "         1.23129845e-01,  8.56838673e-02, -1.56609535e-01,\n",
      "        -1.27697110e-01],\n",
      "       [ 1.95753723e-02, -6.63016886e-02,  1.30141824e-02,\n",
      "         2.76767928e-02, -3.44424620e-02,  3.92978042e-02,\n",
      "         5.05526550e-02, -5.25370911e-02, -3.88029367e-02,\n",
      "        -6.39644451e-03],\n",
      "       [ 2.11090848e-01, -2.83745229e-01,  3.65779810e-02,\n",
      "         2.85095610e-02, -2.34931260e-02,  4.11867388e-02,\n",
      "         1.30671784e-02, -3.93030792e-03, -2.42590263e-01,\n",
      "        -4.02898788e-02],\n",
      "       [ 1.81141794e-01, -3.37841779e-01,  1.12994514e-01,\n",
      "        -2.88403705e-02, -1.92396373e-01, -1.70339942e-02,\n",
      "         2.04947889e-01,  5.92036843e-02, -1.37502417e-01,\n",
      "        -1.25579387e-01],\n",
      "       [ 1.37473986e-01, -6.17838576e-02,  2.42818594e-02,\n",
      "        -4.88483533e-02, -2.27512754e-02, -4.38422635e-02,\n",
      "         1.40101425e-02,  1.89208180e-01, -2.73643304e-02,\n",
      "         4.38259095e-02],\n",
      "       [ 1.37770995e-01, -1.95421547e-01,  8.27945471e-02,\n",
      "        -5.11158891e-02, -1.46871895e-01, -4.40512337e-02,\n",
      "         1.36922881e-01,  3.38321365e-02, -6.93419352e-02,\n",
      "         7.48251379e-02],\n",
      "       [ 1.42696083e-01, -2.57114649e-01,  7.77321011e-02,\n",
      "        -3.41028869e-02, -1.32499710e-01,  2.23793611e-02,\n",
      "         5.32371849e-02,  8.72942060e-02, -8.10581073e-02,\n",
      "        -6.02141619e-02],\n",
      "       [ 1.80777013e-01, -4.03917909e-01,  6.90800399e-02,\n",
      "        -2.51645818e-02, -1.23742625e-01, -4.05675992e-02,\n",
      "         1.58395991e-01, -4.84118313e-02, -1.65474027e-01,\n",
      "         2.75065750e-03],\n",
      "       [ 8.19395036e-02, -2.05518156e-01,  7.86826313e-02,\n",
      "         8.60604942e-02, -1.14381023e-01,  1.78768933e-02,\n",
      "         6.73884302e-02, -4.87268753e-02, -5.19034900e-02,\n",
      "        -1.28923394e-02],\n",
      "       [ 8.34569931e-02, -2.35908389e-01, -1.88448504e-02,\n",
      "        -2.51799859e-02, -9.28956643e-02, -3.55080329e-02,\n",
      "         1.06324434e-01, -2.64462829e-02, -8.51299688e-02,\n",
      "        -1.65816441e-01],\n",
      "       [ 1.38177112e-01, -8.78564119e-02,  3.55074555e-02,\n",
      "         1.48693472e-02, -7.11714923e-02, -1.00443840e-01,\n",
      "         1.47152349e-01,  9.27866548e-02, -1.08396456e-01,\n",
      "        -1.49118602e-02],\n",
      "       [ 8.80307406e-02, -3.10434043e-01,  6.94117248e-02,\n",
      "         4.18802537e-03, -1.08778998e-01, -4.30073291e-02,\n",
      "         8.84500146e-02,  4.38911989e-02, -1.53112322e-01,\n",
      "        -5.85531518e-02],\n",
      "       [ 2.34211773e-01, -3.66408825e-01, -1.79111585e-02,\n",
      "         6.03636056e-02, -1.43945143e-01,  4.89909239e-02,\n",
      "        -8.40552300e-02, -1.03743076e-02, -9.86053273e-02,\n",
      "         4.31424566e-02],\n",
      "       [ 1.02573961e-01, -1.71199620e-01, -2.37351842e-02,\n",
      "         4.09821328e-03, -2.38268785e-02, -1.18338242e-02,\n",
      "         1.08704492e-02,  2.90585421e-02, -6.05013967e-02,\n",
      "         3.61278653e-03],\n",
      "       [ 8.79913270e-02, -1.94176421e-01, -2.00331323e-02,\n",
      "        -2.16388889e-02, -7.72256553e-02,  1.26879945e-01,\n",
      "         7.20053166e-03,  4.87994403e-05, -2.52155736e-02,\n",
      "        -7.43481815e-02],\n",
      "       [ 1.55093133e-01, -1.88648060e-01,  1.71378314e-01,\n",
      "         4.07023504e-02, -2.79899277e-02,  7.33412281e-02,\n",
      "         1.95677489e-01, -5.18236943e-02, -2.44920149e-01,\n",
      "        -1.47026524e-01],\n",
      "       [ 8.88790637e-02, -7.06918687e-02,  8.23669136e-03,\n",
      "         3.28989029e-02, -4.74687740e-02, -3.91436554e-02,\n",
      "         2.02782646e-01, -5.95949031e-02, -1.41937882e-01,\n",
      "        -1.76825047e-01],\n",
      "       [ 8.08424950e-02, -2.05268264e-01, -2.22340673e-02,\n",
      "         5.69474809e-02, -1.63213357e-01, -7.66383857e-03,\n",
      "         1.01891026e-01,  1.39792293e-01,  7.43784755e-03,\n",
      "         1.46049857e-02],\n",
      "       [ 4.65198010e-02, -1.18421592e-01,  5.71081787e-03,\n",
      "        -1.99123714e-02, -2.86436118e-02, -1.18452031e-02,\n",
      "         7.82068148e-02, -7.94757456e-02, -1.25772312e-01,\n",
      "        -2.60711517e-02],\n",
      "       [ 1.99550956e-01, -3.14251661e-01,  1.25800818e-02,\n",
      "        -3.17056216e-02, -1.84959501e-01, -1.89967565e-02,\n",
      "         1.46765903e-01, -7.49615878e-02, -9.53090489e-02,\n",
      "         1.35244187e-02],\n",
      "       [ 3.55243273e-02, -2.14189321e-01, -7.25452676e-02,\n",
      "        -6.59273565e-03, -1.28400885e-02, -1.16234273e-03,\n",
      "        -1.04160756e-02,  1.14769824e-01,  4.23721373e-02,\n",
      "         8.35013017e-02],\n",
      "       [ 1.50340393e-01, -1.05201721e-01,  6.84968680e-02,\n",
      "         3.05669941e-02, -1.56205803e-01,  5.06962836e-03,\n",
      "         1.52017191e-01,  4.91600484e-02, -8.51629376e-02,\n",
      "        -1.06258251e-01],\n",
      "       [ 1.86911039e-03, -1.51550382e-01,  1.17743239e-02,\n",
      "        -8.72416645e-02, -8.68112147e-02,  3.39231119e-02,\n",
      "         4.37024832e-02, -2.23021675e-02, -9.70169753e-02,\n",
      "         2.56811678e-02],\n",
      "       [ 1.16186142e-01, -1.02433823e-01, -6.49472773e-02,\n",
      "         3.55430171e-02, -5.40682226e-02,  7.80661404e-02,\n",
      "         5.08949235e-02,  1.28508121e-01, -7.03311861e-02,\n",
      "        -5.55767156e-02],\n",
      "       [ 1.71947837e-01, -2.27554902e-01,  1.12310968e-01,\n",
      "         6.67985454e-02, -2.50421464e-03,  4.48588282e-04,\n",
      "         1.31396815e-01,  4.60651964e-02, -2.85277605e-01,\n",
      "        -1.54619426e-01],\n",
      "       [ 9.04485509e-02, -1.53403699e-01,  4.04663347e-02,\n",
      "         9.91863385e-03, -2.72045955e-02, -1.21520497e-02,\n",
      "         3.10486741e-02, -2.25084275e-02, -1.05380222e-01,\n",
      "         9.88293067e-03],\n",
      "       [ 2.85415828e-01, -2.26620391e-01,  1.64607465e-02,\n",
      "         6.41832799e-02, -1.54512525e-02,  5.29760048e-02,\n",
      "         8.19145665e-02,  1.95806518e-01, -1.91747159e-01,\n",
      "        -4.67150137e-02],\n",
      "       [ 1.44423053e-01, -3.01142633e-01,  5.19012064e-02,\n",
      "        -3.03523019e-02, -1.07664317e-01,  4.88068052e-02,\n",
      "         2.54983976e-02, -1.21741220e-02, -1.48139864e-01,\n",
      "         3.94036807e-02],\n",
      "       [ 1.47695377e-01, -2.07773745e-01,  4.62337583e-02,\n",
      "         1.31908700e-01, -4.77908961e-02,  2.77673639e-02,\n",
      "         9.66634601e-03,  1.09004922e-01, -1.16734572e-01,\n",
      "         6.88606501e-02],\n",
      "       [ 1.03634521e-01, -2.72952735e-01,  9.33039337e-02,\n",
      "         8.69573802e-02, -1.33137301e-01, -5.01692779e-02,\n",
      "         6.97830170e-02, -7.55320936e-02, -1.41739622e-01,\n",
      "        -6.78976849e-02],\n",
      "       [ 1.06849074e-01, -1.84772417e-01,  8.95364657e-02,\n",
      "         7.14784488e-02, -8.10323730e-02,  7.74582475e-02,\n",
      "         6.44342899e-02, -5.20523898e-02, -1.76087245e-01,\n",
      "        -4.41263206e-02],\n",
      "       [ 8.01230669e-02, -1.45829022e-01,  1.27984345e-01,\n",
      "        -2.54378784e-02, -1.72845364e-01, -3.67196649e-03,\n",
      "         1.65524147e-02,  2.18645334e-02, -4.70805466e-02,\n",
      "        -6.07568920e-02],\n",
      "       [ 2.71336198e-01, -2.65550196e-01,  2.60874480e-02,\n",
      "        -3.91726196e-03, -3.06420289e-02, -1.12165965e-01,\n",
      "         8.77269879e-02,  1.38617188e-01, -1.80567384e-01,\n",
      "        -1.23042606e-01],\n",
      "       [ 1.12579219e-01, -2.32007965e-01,  8.63358527e-02,\n",
      "        -2.00997815e-02, -2.17423558e-01,  1.46582089e-02,\n",
      "         1.13442279e-01,  8.59252661e-02, -6.22012019e-02,\n",
      "         4.07065637e-02],\n",
      "       [ 1.13179669e-01, -1.43530339e-01,  6.30862936e-02,\n",
      "         2.57700384e-02, -8.49790201e-02, -7.14672282e-02,\n",
      "         1.56494290e-01, -4.96934503e-02, -1.42485321e-01,\n",
      "        -8.69153067e-02],\n",
      "       [ 1.16933331e-01, -2.19553173e-01,  5.76893166e-02,\n",
      "         7.28537440e-02, -1.59825042e-01,  4.11896482e-02,\n",
      "         1.74791291e-01, -6.24563508e-02, -1.73232391e-01,\n",
      "        -1.36193216e-01],\n",
      "       [ 1.50829941e-01, -2.25219905e-01,  1.01536565e-01,\n",
      "         6.07888252e-02, -6.25048950e-02,  7.20896050e-02,\n",
      "         1.06562912e-01,  4.47168946e-04, -1.20307669e-01,\n",
      "        -5.42154051e-02],\n",
      "       [ 1.99102953e-01, -2.48793215e-01,  7.31401667e-02,\n",
      "         6.93217814e-02, -1.61027700e-01,  5.28271124e-03,\n",
      "         1.13453656e-01, -3.14607993e-02, -1.07732221e-01,\n",
      "        -1.08008727e-01],\n",
      "       [ 1.38328165e-01, -4.22267616e-03,  1.74680427e-02,\n",
      "        -3.36153060e-02, -6.78008199e-02, -3.17606032e-02,\n",
      "         7.04128593e-02,  9.42409635e-02, -3.00518237e-02,\n",
      "         4.27855998e-02],\n",
      "       [ 2.12617606e-01, -2.99683511e-01,  1.62409842e-01,\n",
      "         1.66243166e-02, -1.53720871e-01,  1.01241879e-02,\n",
      "         1.48515463e-01,  1.23912930e-01, -9.20653939e-02,\n",
      "        -1.20602928e-01],\n",
      "       [ 1.87547475e-01, -1.44004717e-01,  4.97233085e-02,\n",
      "        -2.46492457e-02, -1.54617831e-01, -3.74954231e-02,\n",
      "         1.76990163e-02,  7.12629259e-02, -1.44083351e-01,\n",
      "        -2.99077481e-03],\n",
      "       [ 8.89945105e-02, -1.05510533e-01, -2.93245353e-02,\n",
      "         1.64474137e-02, -9.23269093e-02, -5.59005886e-04,\n",
      "         9.08045918e-02,  1.68739669e-02, -6.56834543e-02,\n",
      "         4.58198115e-02],\n",
      "       [ 1.68633655e-01, -3.15440297e-01,  9.87913385e-02,\n",
      "         5.69747314e-02, -1.22252390e-01,  6.93495199e-02,\n",
      "         1.78802013e-01,  1.19574219e-01, -2.01008558e-01,\n",
      "        -1.30682662e-01],\n",
      "       [ 1.12698339e-01, -8.39850754e-02,  1.28045306e-03,\n",
      "        -4.32496741e-02, -9.08113793e-02, -2.36964636e-02,\n",
      "        -3.23375352e-02,  1.59308851e-01,  6.71649799e-02,\n",
      "         1.06286608e-01],\n",
      "       [ 8.84962082e-02, -8.77688080e-02,  2.91030705e-02,\n",
      "         1.65279955e-03, -2.81104688e-02, -1.09382160e-01,\n",
      "         8.25178400e-02,  3.51370834e-02, -6.47382215e-02,\n",
      "        -6.30832762e-02],\n",
      "       [ 1.71750352e-01, -2.38583833e-01,  4.11464274e-02,\n",
      "        -3.72004025e-02, -1.43957645e-01,  4.91107404e-02,\n",
      "        -9.48989391e-03,  4.14304100e-02, -1.11518845e-01,\n",
      "         2.66138837e-02],\n",
      "       [ 1.30051881e-01, -1.84456408e-01,  8.72039050e-03,\n",
      "        -5.94134852e-02, -1.03170224e-01,  3.01133618e-02,\n",
      "         8.10889602e-02, -1.40480176e-02, -1.76957116e-01,\n",
      "        -2.34120674e-02],\n",
      "       [ 1.97964907e-01, -2.65603721e-01, -1.02177635e-02,\n",
      "        -2.02472582e-02, -1.44539356e-01, -3.10033225e-02,\n",
      "         1.25215396e-01,  3.86336520e-02, -1.76335335e-01,\n",
      "         2.26367004e-02],\n",
      "       [ 1.52395889e-01, -1.72641754e-01,  2.91320533e-02,\n",
      "         1.69216059e-02, -4.63872030e-02, -5.21881431e-02,\n",
      "         7.36403912e-02,  1.16167501e-01, -1.48858696e-01,\n",
      "        -6.89277798e-03],\n",
      "       [ 1.38520181e-01, -2.21183941e-01, -5.37112355e-03,\n",
      "         1.28165735e-02, -1.21752948e-01, -5.14230281e-02,\n",
      "         7.42741823e-02, -8.05972517e-03, -1.83900625e-01,\n",
      "        -1.61556512e-01],\n",
      "       [ 7.76374117e-02, -2.69544601e-01, -5.02528064e-02,\n",
      "        -5.47325611e-02, -5.57238273e-02,  8.90205503e-02,\n",
      "        -2.71422751e-02, -9.67182219e-03, -4.58855331e-02,\n",
      "         2.22984366e-02],\n",
      "       [ 1.73109919e-01, -1.86981618e-01, -1.07379034e-01,\n",
      "         3.51453945e-02, -7.06118494e-02,  3.06907482e-02,\n",
      "         6.51141554e-02,  3.62586752e-02, -8.01420659e-02,\n",
      "        -8.44963267e-03],\n",
      "       [ 1.01186842e-01, -1.03504345e-01, -1.06271729e-02,\n",
      "        -1.39176100e-02, -9.08325911e-02, -6.89803511e-02,\n",
      "         1.43685207e-01,  6.79614693e-02, -8.00314844e-02,\n",
      "         3.09409201e-03],\n",
      "       [ 1.83373183e-01, -2.88777769e-01,  1.73106775e-01,\n",
      "         3.24123055e-02, -1.02930009e-01,  3.42867188e-02,\n",
      "         1.20540455e-01,  3.31402868e-02, -1.85105324e-01,\n",
      "        -9.63809416e-02],\n",
      "       [ 6.88238293e-02, -1.40648097e-01,  2.70645432e-02,\n",
      "         6.98859990e-02, -7.55100846e-02, -1.90960746e-02,\n",
      "         1.25096366e-03,  1.79661065e-03, -1.02877662e-01,\n",
      "        -1.51238833e-02],\n",
      "       [ 1.78445086e-01, -1.35213643e-01,  2.82063894e-02,\n",
      "         6.88501969e-02, -1.33073516e-02, -7.33393729e-02,\n",
      "         5.36525771e-02,  4.37953472e-02, -1.48098364e-01,\n",
      "         2.72138119e-02]], dtype=float32)>,\n",
      "  1: <tf.Tensor: shape=(64, 10), dtype=float32, numpy=\n",
      "array([[ 1.27885044e-01, -2.46666372e-01,  6.10609949e-02,\n",
      "         5.92685156e-02, -1.16793141e-01,  3.48639004e-02,\n",
      "         1.55070916e-01,  5.65104187e-02, -1.22155793e-01,\n",
      "        -4.20930646e-02],\n",
      "       [ 1.15872577e-01, -1.84752017e-01, -5.71194962e-02,\n",
      "        -2.12614611e-02, -9.98550504e-02,  1.10701919e-02,\n",
      "         1.60223812e-01,  5.52013516e-03, -1.10808961e-01,\n",
      "         3.24809998e-02],\n",
      "       [ 1.78615242e-01, -2.25994438e-01,  1.19417734e-01,\n",
      "        -1.42031908e-03, -6.84399307e-02,  1.91914812e-02,\n",
      "         1.65670529e-01,  4.86450642e-02, -1.44869775e-01,\n",
      "        -1.78900450e-01],\n",
      "       [ 5.76383621e-03, -8.49595964e-02, -2.43893713e-02,\n",
      "         6.89533502e-02, -5.31295221e-03, -8.38937238e-04,\n",
      "         2.82113031e-02,  3.61816697e-02, -4.08098660e-02,\n",
      "         2.59497818e-02],\n",
      "       [ 1.76921219e-01, -3.15236866e-01,  1.10127069e-01,\n",
      "        -8.51884484e-03, -1.87771827e-01,  6.48858398e-03,\n",
      "         3.52341011e-02,  6.73333406e-02, -4.66764718e-02,\n",
      "        -2.54447237e-02],\n",
      "       [ 9.79562625e-02, -2.42872879e-01, -1.49208345e-02,\n",
      "        -1.20885670e-06, -4.69806530e-02, -7.70475417e-02,\n",
      "         5.06212115e-02, -6.41435087e-02, -1.86235204e-01,\n",
      "        -3.10107730e-02],\n",
      "       [ 7.08691403e-02, -1.16873421e-01, -9.42983851e-03,\n",
      "         2.27671117e-03,  1.45658301e-02, -7.89136142e-02,\n",
      "         6.70566186e-02,  1.31644204e-01, -1.49833467e-02,\n",
      "         7.93657303e-02],\n",
      "       [ 1.86089694e-01, -2.50324190e-01,  1.13102704e-01,\n",
      "         3.89533602e-02, -1.43481359e-01, -6.45611808e-03,\n",
      "         7.22613558e-02,  4.79452685e-03, -1.19379878e-01,\n",
      "        -8.94017220e-02],\n",
      "       [ 1.49628833e-01, -2.16814831e-01, -6.96402788e-03,\n",
      "         1.93740204e-02, -3.62833068e-02, -4.06554714e-02,\n",
      "         1.50012195e-01,  3.59057933e-02, -1.78931803e-01,\n",
      "        -1.15502670e-01],\n",
      "       [ 1.63735747e-01, -1.43615663e-01,  4.69809175e-02,\n",
      "        -5.90279698e-04, -7.05487207e-02, -7.57674724e-02,\n",
      "         7.80205950e-02,  6.56433553e-02, -1.64821565e-01,\n",
      "        -3.91464680e-04],\n",
      "       [ 1.26897953e-02, -5.01747802e-02, -5.16617298e-03,\n",
      "         6.06552139e-03, -4.10623625e-02,  4.56354581e-02,\n",
      "         1.76724494e-02,  2.98884623e-02,  3.63355130e-03,\n",
      "         5.01044393e-02],\n",
      "       [ 6.56843111e-02, -2.60651082e-01, -1.38901398e-02,\n",
      "        -1.73517112e-02, -1.21665627e-01, -1.04290918e-02,\n",
      "         1.27930671e-01, -9.25720483e-02, -1.58776075e-01,\n",
      "        -7.63121694e-02],\n",
      "       [ 8.36120993e-02, -2.00590909e-01,  4.21527401e-02,\n",
      "         6.50077611e-02, -8.55429247e-02,  6.01949394e-02,\n",
      "         1.33191377e-01,  4.96718735e-02, -1.61278158e-01,\n",
      "        -5.53168356e-04],\n",
      "       [ 6.77295700e-02, -2.03086168e-01,  8.10615718e-03,\n",
      "        -2.12259516e-02, -1.39885053e-01,  1.17493905e-02,\n",
      "         8.93364996e-02,  3.86537649e-02, -5.11981249e-02,\n",
      "         2.95043886e-02],\n",
      "       [ 9.55446064e-02, -1.63773730e-01, -7.08613992e-02,\n",
      "         2.62736268e-02, -7.58625865e-02, -2.06121802e-03,\n",
      "         1.04235694e-01,  7.80706555e-02, -7.82580078e-02,\n",
      "         3.35763246e-02],\n",
      "       [-2.68600509e-03, -7.47267455e-02,  3.05374712e-03,\n",
      "         2.12906729e-02, -2.69198082e-02, -8.48305821e-02,\n",
      "         9.39091668e-02,  4.27491181e-02,  5.97379357e-03,\n",
      "         1.54054165e-03],\n",
      "       [ 3.16542149e-01, -3.66938829e-01,  9.62305665e-02,\n",
      "        -3.13103572e-03, -7.22732991e-02,  7.06394017e-03,\n",
      "         1.17471784e-01,  6.95461631e-02, -2.31973529e-01,\n",
      "        -1.68918461e-01],\n",
      "       [ 1.89187884e-01, -3.91187459e-01,  4.67585213e-02,\n",
      "         8.95505399e-03, -1.43740714e-01, -5.67009896e-02,\n",
      "         7.82376975e-02, -3.87473516e-02, -1.66953027e-01,\n",
      "         5.54143749e-02],\n",
      "       [ 3.83565985e-02, -1.45506427e-01, -4.69468199e-02,\n",
      "        -3.17817926e-03, -6.44920021e-02,  2.83019096e-02,\n",
      "        -3.06543037e-02,  1.64629489e-01,  1.73046105e-02,\n",
      "         3.22597697e-02],\n",
      "       [ 5.32256514e-02, -1.92764401e-01,  1.59556121e-02,\n",
      "         1.05027430e-01, -6.49360567e-02, -3.22996527e-02,\n",
      "         8.86313990e-02,  3.03415172e-02, -1.77735567e-01,\n",
      "        -1.91540644e-02],\n",
      "       [ 1.89158231e-01, -1.87466145e-01, -1.91907883e-02,\n",
      "         2.67856568e-03, -5.02583720e-02, -8.62729922e-02,\n",
      "         1.12799689e-01,  1.70333266e-01, -5.92950433e-02,\n",
      "         1.18697166e-01],\n",
      "       [ 1.99711189e-01, -1.12967432e-01,  7.96890184e-02,\n",
      "         6.03392050e-02,  3.79058048e-02,  9.56646353e-03,\n",
      "         1.51658617e-02,  5.44389337e-03, -1.81115925e-01,\n",
      "        -6.87612668e-02],\n",
      "       [ 7.68725425e-02, -2.67590612e-01,  4.63806167e-02,\n",
      "         1.10034347e-01, -1.72406077e-01,  6.25213236e-02,\n",
      "        -3.97406295e-02,  1.06628135e-01, -2.36582905e-02,\n",
      "         3.07434909e-02],\n",
      "       [ 6.65293038e-02, -1.82442263e-01,  5.69735989e-02,\n",
      "         2.18663830e-02, -6.48378283e-02, -6.76428527e-02,\n",
      "         1.39767185e-01, -7.41331056e-02, -1.65435642e-01,\n",
      "        -9.70883518e-02],\n",
      "       [ 2.01058596e-01, -2.61317432e-01, -1.84001699e-02,\n",
      "         6.33071959e-02, -2.67550349e-03, -1.38270892e-02,\n",
      "         1.18393995e-01,  9.25516039e-02, -1.43898085e-01,\n",
      "        -1.81777164e-01],\n",
      "       [ 2.66967833e-01, -2.88913816e-01,  9.67910215e-02,\n",
      "        -3.84363271e-02, -1.85001448e-01,  3.13463435e-02,\n",
      "         1.20091312e-01,  4.58185002e-02, -1.53159901e-01,\n",
      "        -2.07820572e-02],\n",
      "       [ 9.00611654e-02, -1.31268799e-01, -3.55406478e-03,\n",
      "        -7.53392875e-02, -6.13245592e-02, -7.31819123e-03,\n",
      "         7.10753649e-02,  7.09620118e-02, -8.13134611e-02,\n",
      "         9.47821811e-02],\n",
      "       [ 1.93869412e-01, -2.27815628e-01,  9.92562696e-02,\n",
      "         3.57618257e-02, -5.27647361e-02, -8.50399882e-02,\n",
      "         7.01466426e-02,  6.12566397e-02, -1.26461953e-01,\n",
      "        -1.15291402e-01],\n",
      "       [ 3.62229533e-02, -9.56141502e-02,  6.54015392e-02,\n",
      "         5.92482425e-02,  6.29962981e-03, -1.02086797e-01,\n",
      "         9.97735411e-02, -1.57521851e-03, -5.39299026e-02,\n",
      "        -5.78723028e-02],\n",
      "       [-3.74699943e-03, -9.68191177e-02,  2.20198110e-02,\n",
      "         5.78998737e-02, -2.86683831e-02, -2.87471954e-02,\n",
      "         8.07546973e-02,  1.06133707e-02, -2.48439610e-03,\n",
      "        -3.79150473e-02],\n",
      "       [ 6.77859634e-02, -1.86870977e-01,  3.07906345e-02,\n",
      "        -1.07684545e-02, -6.36681765e-02, -8.39179978e-02,\n",
      "         9.85609591e-02,  1.28829136e-01, -5.84729463e-02,\n",
      "         5.23564368e-02],\n",
      "       [ 7.90519267e-02, -5.69423065e-02, -3.77275795e-03,\n",
      "         6.29761219e-02, -4.18563001e-02, -7.02205151e-02,\n",
      "         6.42244965e-02,  3.84026617e-02, -6.34890199e-02,\n",
      "        -1.45601146e-02],\n",
      "       [ 3.99283431e-02, -1.67437077e-01,  5.26406020e-02,\n",
      "         9.17010084e-02, -1.04780704e-01, -2.69896705e-02,\n",
      "         4.59531210e-02, -1.88221671e-02, -5.26715294e-02,\n",
      "         1.33575667e-02],\n",
      "       [ 1.64025575e-01, -8.50998834e-02,  1.93232782e-02,\n",
      "        -6.94485530e-02, -1.01411864e-01, -2.13257670e-02,\n",
      "         9.18813199e-02,  1.11052282e-01, -6.62977323e-02,\n",
      "         7.83713162e-03],\n",
      "       [ 4.78624664e-02, -6.54663891e-02, -1.04190670e-02,\n",
      "         2.60893814e-02, -2.12309733e-02, -1.55553408e-02,\n",
      "         5.87825105e-02,  3.11466493e-02, -7.78730214e-03,\n",
      "        -7.10255280e-03],\n",
      "       [ 2.66455829e-01, -3.26354086e-01, -3.67345028e-02,\n",
      "         6.28823489e-02, -1.37245595e-01, -2.08172575e-03,\n",
      "         9.50635821e-02, -3.36158499e-02, -2.23693013e-01,\n",
      "        -7.32927471e-02],\n",
      "       [ 9.71049517e-02, -1.49090379e-01, -1.67229921e-02,\n",
      "        -1.99327189e-02, -3.14421989e-02, -6.04505464e-02,\n",
      "         1.28427938e-01,  5.42176515e-03, -1.67008087e-01,\n",
      "        -1.57183595e-02],\n",
      "       [ 3.02089453e-01, -3.65109324e-01,  1.32298410e-01,\n",
      "         5.61413728e-02, -8.09673443e-02,  1.22207098e-01,\n",
      "         3.69112641e-02,  7.63800740e-02, -1.84713438e-01,\n",
      "        -9.88921598e-02],\n",
      "       [ 1.06831625e-01, -1.52416468e-01, -2.29629055e-02,\n",
      "         3.14386450e-02, -4.54321057e-02, -3.33097875e-02,\n",
      "        -5.76151162e-03,  2.20365137e-01,  1.56667735e-02,\n",
      "         2.68171690e-02],\n",
      "       [ 1.36580437e-01, -2.46003568e-01,  1.02501661e-01,\n",
      "         1.32048670e-02, -9.05340537e-02, -6.83012828e-02,\n",
      "         1.27900183e-01,  5.57735525e-02, -1.51475564e-01,\n",
      "         6.83141127e-03],\n",
      "       [ 1.39515564e-01, -1.62621498e-01, -3.87455821e-02,\n",
      "         6.51934445e-02, -3.19160707e-02,  1.45661831e-03,\n",
      "         7.68807530e-02,  7.29631111e-02, -7.86662400e-02,\n",
      "        -1.49219409e-02],\n",
      "       [ 6.13788962e-02, -2.69548178e-01,  1.18900515e-01,\n",
      "         1.12737730e-01, -8.42165053e-02, -4.28909063e-03,\n",
      "         6.08275607e-02, -5.35333529e-03, -1.32040590e-01,\n",
      "        -2.14897394e-02],\n",
      "       [ 1.29430592e-01, -1.69879854e-01,  5.08677363e-02,\n",
      "        -6.63570538e-02, -1.27193436e-01, -3.16529535e-02,\n",
      "         1.52301386e-01,  1.29514225e-02, -1.70265734e-01,\n",
      "        -5.10287769e-02],\n",
      "       [ 1.67749554e-01, -1.68682814e-01, -1.97422504e-02,\n",
      "         4.16205376e-02, -6.93296045e-02, -2.42651030e-02,\n",
      "         1.10124059e-01,  4.05656844e-02, -1.39969587e-01,\n",
      "        -7.01349080e-02],\n",
      "       [-1.04028881e-02, -5.56345582e-02, -1.66911036e-02,\n",
      "         2.40713861e-02,  4.15784121e-03,  4.71809283e-02,\n",
      "         1.90047584e-02, -1.10308323e-02, -2.00496763e-02,\n",
      "         4.83327433e-02],\n",
      "       [ 2.53342360e-01, -3.61683875e-01,  8.94631967e-02,\n",
      "         1.34667251e-02, -7.44774342e-02,  5.18039986e-02,\n",
      "         1.33576021e-01, -2.20271200e-02, -3.30656826e-01,\n",
      "        -1.24956459e-01],\n",
      "       [ 1.24488942e-01, -1.94048434e-01,  1.12591207e-01,\n",
      "        -4.95741591e-02, -1.30783647e-01, -8.21867585e-02,\n",
      "         1.67381003e-01,  6.83536306e-02, -1.19620122e-01,\n",
      "        -5.15734553e-02],\n",
      "       [ 5.60863428e-02, -2.13165015e-01,  9.02202725e-03,\n",
      "         1.54780403e-01, -3.49860117e-02,  1.05738103e-01,\n",
      "         8.18760991e-02, -5.99314719e-02, -1.36598170e-01,\n",
      "        -1.28377333e-01],\n",
      "       [ 6.91584870e-02, -1.32375687e-01,  7.13182688e-02,\n",
      "        -2.55982019e-03, -1.32133961e-01, -6.03656173e-02,\n",
      "         1.57119706e-01,  3.29462886e-02, -3.85527164e-02,\n",
      "         2.84372568e-02],\n",
      "       [ 1.27729736e-02, -1.07306823e-01,  9.01227444e-03,\n",
      "        -1.20804552e-02, -8.12134147e-02, -3.42096668e-03,\n",
      "         7.89515451e-02, -3.02556269e-02, -3.10066342e-02,\n",
      "         2.42812596e-02],\n",
      "       [ 2.20786184e-01, -2.25777328e-01,  8.15835893e-02,\n",
      "        -1.41532868e-02, -9.14084837e-02,  6.05455711e-02,\n",
      "         1.93735033e-01,  5.09279817e-02, -1.43708259e-01,\n",
      "        -1.08355373e-01],\n",
      "       [ 3.54668722e-02, -1.22292228e-01, -6.29182011e-02,\n",
      "        -1.59568451e-02, -4.45853919e-03, -4.20350581e-03,\n",
      "         9.75034386e-02,  1.22882031e-01,  2.62191668e-02,\n",
      "         9.45737362e-02],\n",
      "       [ 1.29813582e-01, -5.81891872e-02,  4.99568135e-03,\n",
      "        -1.68870073e-02, -5.77754118e-02, -1.09626323e-01,\n",
      "         1.72958165e-01,  4.13768515e-02, -1.25800118e-01,\n",
      "        -3.27996835e-02],\n",
      "       [ 6.20602444e-03, -1.06919788e-01,  1.09983012e-02,\n",
      "        -4.35637608e-02, -4.96682003e-02,  1.58199333e-02,\n",
      "        -4.13202494e-03,  1.34374648e-01, -1.75401121e-02,\n",
      "         7.53175467e-02],\n",
      "       [ 2.79235691e-01, -3.46116304e-01,  1.17301166e-01,\n",
      "         3.98727134e-03, -6.18337058e-02,  7.98800588e-02,\n",
      "         6.40892535e-02,  5.22308759e-02, -2.23644450e-01,\n",
      "        -6.86144382e-02],\n",
      "       [ 1.69425577e-01, -2.07581669e-01,  1.12285420e-01,\n",
      "         8.75772983e-02, -1.01843439e-01,  6.67120516e-02,\n",
      "         7.06640258e-02,  5.69561459e-02, -1.47610158e-01,\n",
      "        -1.20118290e-01],\n",
      "       [ 1.14333220e-01, -6.84894919e-02,  8.16385597e-02,\n",
      "         6.77842647e-02, -1.03860795e-01, -3.16225737e-02,\n",
      "         1.53396308e-01,  3.70394625e-02, -1.35988802e-01,\n",
      "        -1.01624839e-01],\n",
      "       [ 2.92404115e-01, -3.93845558e-01,  5.71674928e-02,\n",
      "        -2.51131058e-02, -1.60410091e-01,  3.09475474e-02,\n",
      "         7.53643289e-02,  2.51288787e-02, -1.54129967e-01,\n",
      "        -6.94034472e-02],\n",
      "       [ 8.85679126e-02, -1.08807750e-01,  5.58503717e-02,\n",
      "        -9.01477598e-03, -1.06419198e-01, -4.48017754e-02,\n",
      "         1.28318310e-01,  8.32917094e-02, -6.37922436e-02,\n",
      "        -2.29686238e-02],\n",
      "       [ 4.63552587e-03, -1.37431130e-01, -3.59577984e-02,\n",
      "         2.88817808e-02,  1.93121880e-02, -4.39537615e-02,\n",
      "         3.42130065e-02,  7.91419670e-02, -8.01757276e-02,\n",
      "         4.19560373e-02],\n",
      "       [ 8.51974785e-02, -1.26128271e-01,  4.91543673e-02,\n",
      "         2.47586817e-02, -1.44599870e-01,  3.98865119e-02,\n",
      "         1.51983023e-01,  3.72571349e-02, -1.00875258e-01,\n",
      "        -5.67118041e-02],\n",
      "       [ 4.93021831e-02, -5.30348122e-02,  2.32948065e-02,\n",
      "         1.18169617e-02,  1.75193902e-02,  1.99133325e-02,\n",
      "         3.15895304e-03, -3.82575206e-02, -9.85571146e-02,\n",
      "        -3.87357771e-02],\n",
      "       [ 4.37819548e-02, -1.29934117e-01, -3.73580828e-02,\n",
      "         1.53276622e-02, -2.25356761e-02, -2.21195221e-02,\n",
      "         1.17225915e-01, -3.14791426e-02, -1.28002509e-01,\n",
      "         7.71386921e-03],\n",
      "       [ 1.82949141e-01, -1.19327851e-01,  4.90520149e-03,\n",
      "        -8.00369978e-02, -5.71436062e-02, -5.69989383e-02,\n",
      "         7.82369524e-02,  4.79414277e-02, -6.31392896e-02,\n",
      "        -4.17428203e-02]], dtype=float32)>,\n",
      "  2: <tf.Tensor: shape=(64, 10), dtype=float32, numpy=\n",
      "array([[ 1.99086890e-02, -1.18299082e-01, -5.09649515e-04,\n",
      "         6.69284016e-02, -8.31833929e-02,  2.47789174e-02,\n",
      "         1.09678909e-01, -6.57006949e-02, -6.55488595e-02,\n",
      "        -1.36098862e-01],\n",
      "       [ 1.49800882e-01, -2.26246357e-01,  1.61927938e-03,\n",
      "         1.80277340e-02, -7.24180490e-02,  4.12681997e-02,\n",
      "         4.12922613e-02,  8.69020075e-02, -1.77083746e-01,\n",
      "         5.42148575e-03],\n",
      "       [ 1.25505716e-01, -1.46150410e-01, -7.57971033e-03,\n",
      "        -1.04201481e-01, -1.05630115e-01, -2.59995013e-02,\n",
      "         1.24512076e-01,  5.85957877e-02, -7.12437481e-02,\n",
      "         5.04249185e-02],\n",
      "       [ 2.30737314e-01, -3.29748571e-01,  1.10920988e-01,\n",
      "         5.40469140e-02, -9.02851447e-02,  5.63502088e-02,\n",
      "         5.74141629e-02,  5.98804355e-02, -2.30635077e-01,\n",
      "        -1.15260467e-01],\n",
      "       [ 1.08695909e-01, -1.05851710e-01, -3.79128158e-02,\n",
      "         4.51071262e-02, -2.87510157e-02,  4.73653153e-02,\n",
      "        -1.29062757e-02,  5.98394498e-03, -1.00353345e-01,\n",
      "        -1.17310762e-01],\n",
      "       [ 1.61498696e-01, -3.26610357e-01,  8.05005133e-02,\n",
      "         1.71714544e-01, -9.03970897e-02,  8.17581192e-02,\n",
      "         9.75183249e-02, -7.28197768e-02, -1.07868716e-01,\n",
      "        -1.71384990e-01],\n",
      "       [ 1.21108338e-01, -1.31294638e-01, -3.59654129e-02,\n",
      "         7.17959553e-02,  1.44487135e-02, -3.97857912e-02,\n",
      "         6.32279068e-02,  1.38185635e-01, -1.74389094e-01,\n",
      "         1.69183258e-02],\n",
      "       [ 1.00826427e-01, -1.62813425e-01,  6.60581887e-02,\n",
      "         6.85117096e-02, -1.16659135e-01, -2.51427125e-02,\n",
      "         3.96192186e-02,  4.79074419e-02, -1.85138136e-02,\n",
      "        -1.91030093e-02],\n",
      "       [ 2.86910180e-02, -9.00120884e-02,  3.93116102e-02,\n",
      "         2.58334447e-02, -5.80003299e-02, -2.57440098e-03,\n",
      "         6.70223534e-02, -2.94831172e-02, -2.25386396e-02,\n",
      "        -1.40298223e-02],\n",
      "       [ 7.66111538e-02, -6.82412758e-02,  3.55873182e-02,\n",
      "         2.25770194e-02, -2.21704319e-02, -5.50767295e-02,\n",
      "         1.16521202e-01, -3.95722687e-04, -4.66949865e-02,\n",
      "        -6.52008131e-02],\n",
      "       [ 1.90626800e-01, -1.78208202e-01, -1.17898956e-02,\n",
      "         4.52186540e-03, -6.41462654e-02, -2.84481235e-02,\n",
      "         1.91934071e-02,  1.31951049e-02, -8.37352425e-02,\n",
      "        -1.46341110e-02],\n",
      "       [ 1.08117163e-01, -1.47211328e-01,  6.64647594e-02,\n",
      "         1.30034126e-02, -5.92802688e-02, -5.52572459e-02,\n",
      "         6.90619126e-02,  1.21193103e-01, -9.70066115e-02,\n",
      "         2.86763571e-02],\n",
      "       [ 1.58437029e-01, -2.21591622e-01,  9.35730338e-03,\n",
      "         2.01131757e-02, -1.37784064e-01, -5.62573820e-02,\n",
      "         7.02252537e-02,  4.55708057e-02, -1.86293170e-01,\n",
      "        -8.43652040e-02],\n",
      "       [ 1.67793900e-01, -1.52516231e-01,  7.15897903e-02,\n",
      "         7.57010132e-02, -4.93664257e-02, -4.49585579e-02,\n",
      "         9.89307389e-02, -5.60925677e-02, -1.47269905e-01,\n",
      "        -1.29956588e-01],\n",
      "       [ 1.52405053e-01, -2.64702678e-01,  2.32688636e-02,\n",
      "         1.58944249e-01, -7.74601549e-02,  1.07911929e-01,\n",
      "        -5.37938625e-03,  7.31428117e-02, -4.76112515e-02,\n",
      "        -1.64536983e-02],\n",
      "       [ 2.76000202e-01, -2.64147282e-01, -5.51072061e-02,\n",
      "         6.10502101e-02, -1.12358376e-01,  1.03120834e-01,\n",
      "         1.09085605e-01,  6.32375106e-02, -8.90948921e-02,\n",
      "        -1.08196996e-02],\n",
      "       [ 1.60287946e-01, -1.70183644e-01,  3.88289988e-03,\n",
      "         4.69395965e-02, -3.31258662e-02, -1.21399462e-02,\n",
      "         1.24135226e-01, -4.24484164e-02, -2.25743502e-01,\n",
      "        -1.64331049e-01],\n",
      "       [ 1.23702049e-01, -1.06801137e-01,  3.85086276e-02,\n",
      "        -5.94215766e-02, -9.24396738e-02, -4.75805849e-02,\n",
      "         1.53745770e-01,  1.31310895e-03, -1.50655419e-01,\n",
      "         4.11138125e-02],\n",
      "       [ 5.75363711e-02, -1.52460605e-01, -1.93905830e-02,\n",
      "         2.93618478e-02, -1.06651574e-01, -3.39352489e-02,\n",
      "         6.63267449e-02,  1.82254463e-02, -5.50914742e-02,\n",
      "         1.51493698e-02],\n",
      "       [ 1.51542366e-01, -4.98135909e-02, -5.07678464e-03,\n",
      "        -7.93997049e-02, -1.22898512e-01, -5.74200675e-02,\n",
      "         1.80150792e-01,  4.02402654e-02, -7.00754970e-02,\n",
      "        -2.99639255e-03],\n",
      "       [ 2.93729872e-01, -2.91988134e-01,  9.83853713e-02,\n",
      "         1.80692673e-02, -4.35825661e-02,  7.16883615e-02,\n",
      "         1.02651522e-01,  6.21555373e-02, -1.80277765e-01,\n",
      "        -1.56922981e-01],\n",
      "       [ 1.27452701e-01, -2.61504441e-01, -5.84305823e-03,\n",
      "        -1.30307376e-02, -6.11604080e-02, -3.52911763e-02,\n",
      "         5.25013320e-02, -3.22515741e-02, -1.68141842e-01,\n",
      "        -5.05033806e-02],\n",
      "       [ 1.27830327e-01, -1.80839926e-01,  6.05587140e-02,\n",
      "         1.19829495e-02, -1.18314162e-01, -8.33228603e-03,\n",
      "         6.06215522e-02,  4.40728031e-02, -2.48889476e-02,\n",
      "        -4.71421778e-02],\n",
      "       [ 8.64849053e-03, -9.48932394e-02, -5.82862273e-02,\n",
      "        -4.62751463e-02, -8.91413763e-02,  1.20226936e-02,\n",
      "         1.01917088e-01,  1.11679949e-01,  4.31743488e-02,\n",
      "         1.29187196e-01],\n",
      "       [ 1.54470444e-01, -2.23193020e-01,  3.34921740e-02,\n",
      "         8.71215910e-02, -1.23471543e-01,  2.43844390e-02,\n",
      "         1.35603428e-01, -1.69654042e-02, -1.51649848e-01,\n",
      "        -4.61355001e-02],\n",
      "       [ 1.37748018e-01, -2.43970215e-01,  2.16891691e-02,\n",
      "         8.76856968e-02, -1.83750421e-01,  3.35105993e-02,\n",
      "         1.58057511e-02,  1.21766001e-01,  2.04236656e-02,\n",
      "        -2.83812769e-02],\n",
      "       [ 6.75756857e-02, -1.15049757e-01, -3.97734344e-03,\n",
      "        -2.23360956e-02, -1.18047900e-01, -1.68771297e-03,\n",
      "         1.28711045e-01,  9.10824910e-03, -1.23794109e-01,\n",
      "        -4.14184704e-02],\n",
      "       [ 1.13439873e-01, -2.63516515e-01,  7.00936541e-02,\n",
      "         7.42653199e-03, -8.36165398e-02, -2.55119838e-02,\n",
      "         4.82222177e-02, -9.47414637e-02, -1.97409734e-01,\n",
      "        -3.53264213e-02],\n",
      "       [ 1.66785255e-01, -2.42981404e-01, -5.23246825e-03,\n",
      "        -1.90869048e-02, -2.03238517e-01, -1.80280320e-02,\n",
      "         1.55341566e-01,  6.38855249e-02, -7.29285181e-02,\n",
      "        -4.53866944e-02],\n",
      "       [ 1.35256872e-01, -2.15336680e-01,  3.52459066e-02,\n",
      "        -3.14351581e-02, -1.27391279e-01,  2.34926231e-02,\n",
      "         6.31493554e-02, -9.79364663e-03, -5.98913580e-02,\n",
      "         1.72683019e-02],\n",
      "       [ 2.36514777e-01, -3.06144297e-01,  4.72223908e-02,\n",
      "        -2.51390524e-02, -1.67270333e-01,  2.09238864e-02,\n",
      "         1.78542882e-01,  5.76151311e-02, -1.69851169e-01,\n",
      "        -7.04906434e-02],\n",
      "       [ 1.47906214e-01, -1.27977043e-01,  1.17616639e-01,\n",
      "        -5.50510548e-03, -6.39014840e-02, -3.38953957e-02,\n",
      "         8.13580453e-02, -1.98115110e-02, -9.37554762e-02,\n",
      "        -1.23155683e-01],\n",
      "       [ 1.58563465e-01, -3.11379015e-01,  6.05554879e-02,\n",
      "         7.10094646e-02, -1.52761281e-01,  3.97607125e-02,\n",
      "         3.71359177e-02, -4.77026179e-02, -5.41603491e-02,\n",
      "        -6.91294968e-02],\n",
      "       [ 2.26677850e-01, -3.45731795e-01,  9.72678512e-02,\n",
      "        -5.66386431e-02, -4.58341986e-02, -4.90778051e-02,\n",
      "         1.54168665e-01,  1.15580484e-02, -2.15630978e-01,\n",
      "        -1.53614283e-01],\n",
      "       [ 1.21113941e-01, -7.23675042e-02,  4.52256203e-03,\n",
      "        -7.06283897e-02, -2.52325498e-02, -2.70105675e-02,\n",
      "         2.09800780e-01,  9.54700634e-02, -6.90466315e-02,\n",
      "         1.14207581e-01],\n",
      "       [ 2.37637579e-01, -2.34120190e-01,  1.18098080e-01,\n",
      "        -1.10259205e-01, -2.41631091e-01, -3.07580531e-02,\n",
      "         1.32344872e-01,  8.59988928e-02, -1.18466549e-01,\n",
      "        -5.68656027e-02],\n",
      "       [ 1.89389080e-01, -2.59211004e-01,  9.40684304e-02,\n",
      "         6.50911033e-02, -1.64005876e-01,  7.09105134e-02,\n",
      "         1.31057054e-01, -5.50926812e-02, -2.69368976e-01,\n",
      "        -2.92787217e-02],\n",
      "       [ 9.15603042e-02, -7.48736411e-02, -2.05843896e-03,\n",
      "        -1.37888446e-01, -1.17194057e-01,  3.80388945e-02,\n",
      "        -1.01942569e-02,  2.49259651e-01,  3.29918936e-02,\n",
      "         1.48468792e-01],\n",
      "       [-5.40000200e-03, -1.58397853e-01,  3.28571945e-02,\n",
      "        -6.00184798e-02, -5.84385246e-02, -3.49122137e-02,\n",
      "         1.65357620e-01,  1.22921243e-01, -7.53659904e-02,\n",
      "         1.14809312e-02],\n",
      "       [ 2.06552312e-01, -3.35975409e-01,  2.50989646e-02,\n",
      "         5.21945432e-02, -1.07146963e-01,  3.47564742e-02,\n",
      "         8.42617452e-02, -1.37068033e-02, -1.90948009e-01,\n",
      "        -6.02461249e-02],\n",
      "       [ 1.73392743e-01, -1.18123904e-01,  4.63536307e-02,\n",
      "        -1.86695531e-02, -1.87901650e-02, -8.34226310e-02,\n",
      "         8.43422711e-02,  7.80861080e-02, -1.22561961e-01,\n",
      "         2.46241130e-02],\n",
      "       [ 3.17839086e-01, -3.50495458e-01,  9.96849313e-02,\n",
      "        -4.37931791e-02, -8.02193508e-02,  4.93139438e-02,\n",
      "         1.01354539e-01,  6.51845038e-02, -2.24032074e-01,\n",
      "        -1.70172825e-01],\n",
      "       [ 2.13741973e-01, -2.05324426e-01, -2.04442665e-02,\n",
      "         3.19967382e-02, -1.22797407e-01,  8.48451853e-02,\n",
      "         3.68535519e-02,  7.88279027e-02, -1.06538005e-01,\n",
      "        -4.56362218e-02],\n",
      "       [ 1.03479452e-01, -1.43576637e-01,  3.80221903e-02,\n",
      "        -6.23773746e-02, -1.78798050e-01,  3.95287722e-02,\n",
      "         6.69063479e-02,  1.92946434e-01,  2.98695341e-02,\n",
      "         2.34640911e-02],\n",
      "       [ 1.03736326e-01, -1.55367523e-01, -2.82113999e-03,\n",
      "         3.94254923e-02, -7.02259839e-02,  3.85735221e-02,\n",
      "         7.37018883e-02, -6.25223666e-03, -1.25918329e-01,\n",
      "        -7.64901042e-02],\n",
      "       [ 6.05488196e-02, -1.35546595e-01,  7.41246343e-02,\n",
      "         2.82055791e-02, -2.44041197e-02,  6.75846934e-02,\n",
      "         2.11438071e-02,  6.26247972e-02, -9.91896391e-02,\n",
      "        -5.11676259e-02],\n",
      "       [ 6.40958101e-02, -1.62868008e-01, -2.61689574e-02,\n",
      "        -7.91574270e-03, -1.63719013e-01,  1.48498733e-02,\n",
      "        -2.39525214e-02,  2.54111052e-01,  6.73066974e-02,\n",
      "         1.24313466e-01],\n",
      "       [ 2.63601363e-01, -2.67279714e-01,  6.18229955e-02,\n",
      "        -1.42678246e-02, -1.33891374e-01,  2.78969556e-02,\n",
      "         3.30321267e-02,  8.87694508e-02, -1.14312038e-01,\n",
      "        -3.81142832e-02],\n",
      "       [ 7.76631907e-02, -8.23275149e-02,  1.65616199e-02,\n",
      "         7.23844692e-02, -7.70044103e-02, -1.76761039e-02,\n",
      "         7.57018626e-02, -1.91767737e-02, -2.11364478e-02,\n",
      "        -1.93126928e-02],\n",
      "       [ 1.03861272e-01, -7.95281753e-02,  1.11505449e-01,\n",
      "        -3.01373769e-02, -3.14256474e-02,  1.21443691e-02,\n",
      "         2.26334594e-02,  5.83403297e-02, -5.78931980e-02,\n",
      "        -2.71143392e-03],\n",
      "       [ 1.31511033e-01, -3.17864388e-01, -5.23106605e-02,\n",
      "         5.28486371e-02, -1.11975744e-01,  2.37966832e-02,\n",
      "         1.08769163e-01,  2.01898962e-02, -1.77653655e-01,\n",
      "        -6.46678656e-02],\n",
      "       [ 9.42641050e-02, -1.87936381e-01,  9.70203727e-02,\n",
      "         5.08598238e-02, -1.11506939e-01,  7.63423145e-02,\n",
      "        -1.41387582e-02,  8.06879252e-04, -2.64787935e-02,\n",
      "         6.68242872e-02],\n",
      "       [ 5.84154874e-02, -7.41206557e-02, -4.30397689e-03,\n",
      "         2.63823792e-02, -8.86534154e-02,  2.24945322e-03,\n",
      "         6.24449924e-02,  4.91791219e-03,  1.29501894e-02,\n",
      "         4.14403453e-02],\n",
      "       [ 1.77251548e-01, -3.28018725e-01,  4.21758294e-02,\n",
      "         1.18176624e-01, -1.66284680e-01,  2.46274024e-02,\n",
      "         9.90192741e-02,  5.68202361e-02, -1.04375720e-01,\n",
      "        -8.44068378e-02],\n",
      "       [ 7.16061592e-02, -5.91352955e-02,  1.26830488e-03,\n",
      "        -1.58589184e-02, -5.89829274e-02,  1.73955578e-02,\n",
      "         4.31577414e-02,  9.27123055e-03, -8.12586397e-03,\n",
      "        -5.05773239e-02],\n",
      "       [ 5.34252450e-02, -1.15689509e-01, -3.85283269e-02,\n",
      "         3.44470218e-02, -5.64463772e-02, -2.66508162e-02,\n",
      "         1.03828378e-01, -5.78810386e-02, -3.45733836e-02,\n",
      "         1.77112222e-02],\n",
      "       [ 6.96563944e-02, -7.28312433e-02,  3.85822356e-02,\n",
      "        -1.12106353e-01, -1.84130706e-02, -4.71508503e-02,\n",
      "         9.40193087e-02,  1.32382125e-01, -4.03798744e-02,\n",
      "         6.63202256e-02],\n",
      "       [ 1.20616466e-01, -1.76006392e-01,  6.06995970e-02,\n",
      "        -1.19535923e-02, -1.25546023e-01, -6.73555061e-02,\n",
      "         5.25750034e-02, -5.85914403e-03, -1.42149031e-01,\n",
      "        -1.35314688e-01],\n",
      "       [ 4.45430093e-02, -3.03276572e-02,  4.94690612e-02,\n",
      "         6.06487319e-03,  2.94805840e-02, -2.37799305e-02,\n",
      "         7.84643888e-02,  6.73769116e-02, -5.73738292e-03,\n",
      "        -3.27878967e-02],\n",
      "       [ 5.99569604e-02, -1.74194366e-01,  1.31788552e-02,\n",
      "        -2.48489417e-02, -9.50946584e-02, -7.07104653e-02,\n",
      "         7.19238669e-02,  3.04890126e-02, -6.06462061e-02,\n",
      "         6.85882568e-02],\n",
      "       [ 9.53177810e-02, -2.12965280e-01,  3.85214463e-02,\n",
      "        -9.70859732e-03, -1.46338463e-01,  4.84607816e-02,\n",
      "         7.36515149e-02,  7.81962872e-02, -1.03356630e-01,\n",
      "        -4.61516678e-02],\n",
      "       [ 1.48165345e-01, -2.38766402e-01,  4.59170938e-02,\n",
      "         1.19222172e-01, -1.02554969e-02, -8.06974247e-02,\n",
      "         6.40274435e-02, -4.92060259e-02, -2.28516504e-01,\n",
      "        -1.18880026e-01],\n",
      "       [ 1.42433986e-01, -2.25945935e-01,  9.52820629e-02,\n",
      "         2.56884135e-02, -2.11920142e-01, -3.51343043e-02,\n",
      "        -4.46302965e-02,  1.21341519e-01, -3.68189067e-02,\n",
      "         3.29084694e-04],\n",
      "       [ 1.91503465e-01, -1.10098489e-01,  8.38430524e-02,\n",
      "         5.19769341e-02, -8.84517953e-02, -7.78743327e-02,\n",
      "         1.43743396e-01,  1.27910435e-01, -1.10260636e-01,\n",
      "        -2.67593414e-02]], dtype=float32)>,\n",
      "  3: <tf.Tensor: shape=(64, 10), dtype=float32, numpy=\n",
      "array([[ 1.55930191e-01, -5.95854372e-02, -9.51537341e-02,\n",
      "         1.97939035e-02, -9.13705975e-02,  1.78810954e-02,\n",
      "         9.00360718e-02,  1.57191977e-01, -5.36973551e-02,\n",
      "        -2.19843406e-02],\n",
      "       [ 1.54073685e-01, -1.11792572e-01,  7.94308037e-02,\n",
      "         6.68642893e-02, -9.13412273e-02, -4.13990654e-02,\n",
      "         1.49329126e-01,  1.40528288e-02, -1.55709594e-01,\n",
      "        -1.34351447e-01],\n",
      "       [ 8.02544057e-02, -4.78572883e-02, -1.13128200e-02,\n",
      "        -7.43905902e-02, -9.03891623e-02, -7.05615431e-03,\n",
      "         1.81483999e-02,  1.69111013e-01,  8.17810372e-03,\n",
      "         1.08657256e-01],\n",
      "       [ 1.50779009e-01, -1.11277133e-01,  2.08596773e-02,\n",
      "         5.19825071e-02, -2.70946864e-02, -3.66631709e-02,\n",
      "         3.98920104e-02,  1.13958403e-01, -1.25575081e-01,\n",
      "        -7.60315545e-03],\n",
      "       [ 1.00667626e-01, -1.49804890e-01,  1.70425549e-02,\n",
      "        -1.07546836e-01, -5.46016768e-02, -6.32741451e-02,\n",
      "         1.40364215e-01,  2.67757848e-02, -1.12272836e-01,\n",
      "         7.66827688e-02],\n",
      "       [ 1.36238098e-01, -1.16187342e-01,  1.49570182e-02,\n",
      "        -6.35659248e-02, -1.55948456e-02, -3.29913758e-02,\n",
      "         4.38953564e-02,  3.00220884e-02, -7.26266503e-02,\n",
      "        -6.00622706e-02],\n",
      "       [ 2.70235986e-02, -8.04229230e-02,  2.65898779e-02,\n",
      "         1.96443871e-02, -4.58556116e-02,  5.73398732e-03,\n",
      "         5.42063825e-02, -3.15506905e-02, -2.60907337e-02,\n",
      "         8.53541493e-03],\n",
      "       [ 9.91104096e-02, -2.05552399e-01, -1.54858157e-02,\n",
      "        -6.51729703e-02, -1.83459237e-01,  5.88360205e-02,\n",
      "         1.10120043e-01,  4.84671742e-02, -6.05430305e-02,\n",
      "        -3.97218671e-03],\n",
      "       [ 1.07383639e-01, -1.24965347e-01,  9.19724330e-02,\n",
      "         4.51150239e-02, -9.35338885e-02,  9.76894796e-03,\n",
      "         2.09916860e-01, -4.65418324e-02, -1.29753783e-01,\n",
      "        -8.11312348e-02],\n",
      "       [ 1.28446102e-01, -1.72700167e-01, -2.50982046e-02,\n",
      "         7.19068721e-02, -8.59898254e-02,  5.80850355e-02,\n",
      "         1.36235237e-01,  2.79696658e-03, -3.30999047e-02,\n",
      "        -8.43722969e-02],\n",
      "       [ 2.68472165e-01, -3.69969964e-01,  1.41037613e-01,\n",
      "         2.03329325e-03, -1.68444961e-01,  5.90009019e-02,\n",
      "        -4.02991474e-02,  4.23120111e-02, -1.59692869e-01,\n",
      "        -8.96255970e-02],\n",
      "       [ 1.02896094e-01, -2.58697033e-01,  1.06979609e-01,\n",
      "         1.39155686e-01, -1.94118023e-01, -2.57306900e-02,\n",
      "         3.11022103e-02,  3.91111933e-02, -6.82359040e-02,\n",
      "        -3.41641009e-02],\n",
      "       [ 1.31178096e-01, -1.59546852e-01,  7.70823807e-02,\n",
      "         1.81411933e-02, -6.87068254e-02, -6.23967685e-02,\n",
      "         1.47092253e-01, -4.01412472e-02, -2.02124089e-01,\n",
      "        -1.37845933e-01],\n",
      "       [ 1.38894588e-01, -2.13477105e-01,  4.71255518e-02,\n",
      "        -5.43162525e-02, -1.53828293e-01, -4.50345762e-02,\n",
      "         4.50511239e-02,  1.82030529e-01, -1.33984908e-03,\n",
      "         6.68019354e-02],\n",
      "       [ 1.04664735e-01, -2.13843167e-01,  6.29136413e-02,\n",
      "         3.90464254e-02, -1.84314921e-01,  4.68939729e-02,\n",
      "         8.27086270e-02,  5.09214476e-02, -3.93434167e-02,\n",
      "         2.72851288e-02],\n",
      "       [ 1.39909580e-01, -1.31682649e-01,  8.12229738e-02,\n",
      "        -4.39220853e-03, -8.16902518e-02, -8.53725150e-02,\n",
      "         8.10373276e-02,  1.37043729e-01, -6.64164424e-02,\n",
      "         1.60408653e-02],\n",
      "       [ 1.32347941e-01, -8.47300142e-02, -4.52096872e-02,\n",
      "        -2.36382578e-02, -5.90682402e-02,  2.02781111e-02,\n",
      "         1.01454005e-01,  4.70062606e-02, -3.02681550e-02,\n",
      "         6.19654879e-02],\n",
      "       [-5.90272434e-03, -1.08653575e-01, -3.47647294e-02,\n",
      "         1.92391574e-02, -8.56941752e-03, -3.29914428e-02,\n",
      "        -4.60869893e-02,  7.30581433e-02,  5.85135333e-02,\n",
      "         3.59948725e-03],\n",
      "       [ 1.08222775e-01, -1.42150968e-01,  3.03277150e-02,\n",
      "         8.75964984e-02,  5.18569350e-03,  8.27972814e-02,\n",
      "         5.45808449e-02, -3.50898132e-02, -1.44389808e-01,\n",
      "        -1.01724833e-01],\n",
      "       [ 3.21439356e-01, -3.49961400e-01,  8.97648707e-02,\n",
      "         1.03238970e-02, -8.05300921e-02,  1.19192451e-02,\n",
      "         9.43127871e-02,  9.36765894e-02, -1.49869040e-01,\n",
      "        -8.41590315e-02],\n",
      "       [ 9.65263993e-02, -1.40845105e-01,  1.35765299e-02,\n",
      "         4.90715206e-02, -9.92955267e-02, -3.73904109e-02,\n",
      "         1.34406179e-01,  6.81181252e-03, -2.35903710e-02,\n",
      "        -2.95076612e-02],\n",
      "       [ 2.29147524e-01, -3.44276696e-01,  1.10413320e-01,\n",
      "        -5.52750826e-02, -2.09450603e-01,  3.07433940e-02,\n",
      "         8.77569765e-02,  9.72212553e-02, -9.36580747e-02,\n",
      "        -2.00432166e-02],\n",
      "       [ 8.46759602e-02, -2.18302935e-01,  6.88344389e-02,\n",
      "         7.67964348e-02, -1.60326988e-01,  1.33434683e-03,\n",
      "         1.61436498e-01,  1.17654540e-02, -1.37885869e-01,\n",
      "        -3.99693362e-02],\n",
      "       [ 1.75176054e-01, -1.44516990e-01,  6.13314919e-02,\n",
      "         1.35606229e-02, -6.50275499e-03, -1.07311144e-01,\n",
      "         5.89473248e-02,  4.66354340e-02, -1.43664867e-01,\n",
      "        -3.24210301e-02],\n",
      "       [ 1.78989083e-01, -2.66841561e-01,  1.04531519e-01,\n",
      "        -3.27354930e-02, -1.39905661e-01,  4.29677032e-02,\n",
      "         1.29277363e-01, -4.66909334e-02, -1.98185280e-01,\n",
      "        -1.69813186e-02],\n",
      "       [ 7.97410458e-02, -1.56347916e-01, -1.69430524e-02,\n",
      "         4.66718711e-02, -1.14518210e-01, -4.85013984e-03,\n",
      "         1.20978072e-01, -2.11730599e-04, -1.02752246e-01,\n",
      "        -2.04447843e-02],\n",
      "       [ 1.71688974e-01, -1.60856083e-01,  8.17834884e-02,\n",
      "         2.27832720e-02, -1.59954980e-01, -1.38849355e-02,\n",
      "         6.19734973e-02,  2.55999975e-02, -1.17938437e-01,\n",
      "        -3.21948230e-02],\n",
      "       [ 2.36310750e-01, -3.33596766e-01,  3.12455595e-02,\n",
      "         1.01563901e-01, -5.83848730e-02,  8.75023454e-02,\n",
      "        -3.87299061e-02,  1.02197260e-01, -1.32033169e-01,\n",
      "        -8.75383914e-02],\n",
      "       [ 2.54810359e-02, -3.70554924e-02,  4.45615798e-02,\n",
      "         1.75250489e-02,  8.44433904e-02,  5.10861538e-02,\n",
      "         9.42382142e-02, -7.45707229e-02, -1.40686348e-01,\n",
      "        -4.69042547e-02],\n",
      "       [ 1.01537056e-01, -2.10425407e-01,  1.45389378e-01,\n",
      "         1.85685791e-02, -1.21420637e-01,  6.05402067e-02,\n",
      "        -1.05622701e-01,  1.00927658e-01, -9.95251536e-03,\n",
      "        -4.70631719e-02],\n",
      "       [ 7.08850399e-02, -2.22108185e-01,  9.55490842e-02,\n",
      "         8.27069581e-02, -8.26469213e-02,  6.11465797e-02,\n",
      "        -1.16094500e-02, -5.27828485e-02, -1.15885019e-01,\n",
      "         5.18243313e-02],\n",
      "       [ 3.29715788e-01, -3.13612908e-01, -6.12241775e-03,\n",
      "         1.13853648e-01, -5.03032729e-02,  8.06967914e-03,\n",
      "         1.62531644e-01,  6.59415871e-02, -2.12509841e-01,\n",
      "         1.27977878e-03],\n",
      "       [ 3.39619875e-01, -3.91972303e-01,  8.85933489e-02,\n",
      "        -3.05471234e-02, -1.20262913e-01,  6.04787953e-02,\n",
      "         6.49789125e-02,  3.68731022e-02, -2.51517773e-01,\n",
      "        -8.98065120e-02],\n",
      "       [ 1.95044711e-01, -3.09741080e-01,  1.22452214e-01,\n",
      "        -4.36402112e-03, -9.90841240e-02,  5.20730354e-02,\n",
      "         4.36080620e-03,  8.76479447e-02, -1.19349591e-01,\n",
      "        -6.05513379e-02],\n",
      "       [ 2.00214952e-01, -2.13249922e-01,  1.52568370e-01,\n",
      "        -1.05035305e-03, -5.22367172e-02,  6.04827665e-02,\n",
      "         8.36083293e-02,  1.06783055e-01, -1.32924229e-01,\n",
      "        -1.29709750e-01],\n",
      "       [ 1.30774364e-01, -1.79495052e-01,  6.19825684e-02,\n",
      "        -5.08893281e-05, -5.47186211e-02, -2.32685748e-02,\n",
      "         1.30711570e-02,  7.80923441e-02, -5.32548018e-02,\n",
      "         6.83813691e-02],\n",
      "       [ 1.37058780e-01, -2.97546387e-01,  8.60983878e-02,\n",
      "         9.79922265e-02, -9.17050391e-02, -1.93512067e-04,\n",
      "         2.21372060e-02,  5.17792515e-02, -1.45198271e-01,\n",
      "         2.39564665e-02],\n",
      "       [ 1.51854575e-01, -3.07811350e-01,  5.85288554e-02,\n",
      "         2.71825790e-02, -1.01690598e-01,  3.11207920e-02,\n",
      "         2.07860265e-02,  6.53296411e-02, -1.05385132e-01,\n",
      "        -4.15206067e-02],\n",
      "       [ 1.17928818e-01, -2.10365564e-01, -4.50771563e-02,\n",
      "        -2.67105289e-02, -1.87750384e-01,  7.96425939e-02,\n",
      "         1.16481632e-01,  1.23318985e-01, -1.06438920e-02,\n",
      "         9.73494127e-02],\n",
      "       [ 2.71671772e-01, -2.63200879e-01,  1.55655801e-01,\n",
      "         7.29005858e-02, -3.64517160e-02,  4.19227108e-02,\n",
      "         1.18004873e-01,  9.68050808e-02, -2.80712485e-01,\n",
      "        -9.76329446e-02],\n",
      "       [ 9.14449394e-02, -6.67936727e-02,  3.61688957e-02,\n",
      "         2.94166133e-02, -2.28428245e-02, -7.15101287e-02,\n",
      "         1.12430260e-01,  2.77679227e-02, -8.67272392e-02,\n",
      "        -5.86342737e-02],\n",
      "       [ 1.19631827e-01, -1.76199451e-01,  8.88054371e-02,\n",
      "        -5.79333529e-02, -1.61447689e-01,  1.31010031e-02,\n",
      "        -2.76737921e-02,  1.25910565e-01, -7.01321363e-02,\n",
      "         3.53521109e-02],\n",
      "       [ 1.19876057e-01, -1.13361612e-01, -2.57261433e-02,\n",
      "        -4.72843572e-02, -4.17717062e-02, -4.30146120e-02,\n",
      "        -5.17283268e-02,  1.30386308e-01,  4.24293503e-02,\n",
      "         8.93710554e-02],\n",
      "       [ 1.94169819e-01, -2.65223354e-01,  3.82882431e-02,\n",
      "         1.03008702e-01, -6.13676086e-02,  1.07859813e-01,\n",
      "         6.72024637e-02,  6.80919513e-02, -2.10222095e-01,\n",
      "        -6.00702912e-02],\n",
      "       [ 1.22785389e-01, -2.32885510e-01,  5.83024025e-02,\n",
      "         4.63435128e-02, -9.07529220e-02,  2.89085135e-02,\n",
      "         1.10610694e-01, -7.84037262e-02, -1.43721595e-01,\n",
      "        -1.06894046e-01],\n",
      "       [ 1.53462917e-01, -2.34329149e-01,  2.19478011e-02,\n",
      "         5.20666614e-02, -6.18710145e-02,  2.15046108e-03,\n",
      "         4.65009995e-02,  7.72917271e-03, -2.06512794e-01,\n",
      "        -1.44317150e-02],\n",
      "       [ 8.44687074e-02, -1.63276523e-01,  8.91670585e-03,\n",
      "        -1.00204740e-02, -1.17402092e-01, -4.77838889e-02,\n",
      "         3.61629464e-02, -2.33641900e-02, -6.58508167e-02,\n",
      "         8.33485425e-02],\n",
      "       [ 2.75007486e-01, -3.16218793e-01,  6.56070560e-03,\n",
      "         1.27888322e-02, -1.52386218e-01,  1.14409402e-01,\n",
      "         3.27666402e-02,  1.20601952e-01, -1.16330400e-01,\n",
      "        -5.78423366e-02],\n",
      "       [ 5.35397902e-02, -2.26179808e-01,  5.67623600e-02,\n",
      "        -4.03686017e-02, -1.11849219e-01,  2.52255201e-02,\n",
      "         2.42093116e-01, -2.27400400e-02, -7.09357709e-02,\n",
      "         1.58765018e-02],\n",
      "       [ 1.75934523e-01, -2.08054245e-01,  8.09602365e-02,\n",
      "         5.75007647e-02, -1.16466999e-01, -4.53156643e-02,\n",
      "         9.55019444e-02,  3.91122252e-02, -2.05660030e-01,\n",
      "        -2.10969180e-01],\n",
      "       [ 2.63072968e-01, -3.34022671e-01,  7.75949284e-02,\n",
      "        -2.34512314e-02, -1.88964546e-01,  1.54963434e-02,\n",
      "         1.01806656e-01,  1.00506425e-01, -7.98694119e-02,\n",
      "        -6.06725216e-02],\n",
      "       [ 1.06077157e-02, -9.93775576e-02,  2.10284032e-02,\n",
      "         3.52887884e-02, -3.98235321e-02, -5.13123535e-03,\n",
      "         6.64520115e-02,  2.50905119e-02, -2.88086385e-03,\n",
      "         2.87667308e-02],\n",
      "       [ 1.60640046e-01, -2.37863019e-01,  1.27255619e-02,\n",
      "         3.80289704e-02, -7.33542293e-02, -9.28787142e-03,\n",
      "         6.79433346e-02, -6.27164468e-02, -1.42385989e-01,\n",
      "        -8.91289040e-02],\n",
      "       [-1.52041204e-03, -7.26825595e-02, -9.42894071e-03,\n",
      "         8.61139968e-03, -1.44720245e-02,  5.08274063e-02,\n",
      "         4.08250876e-02, -1.67283006e-02, -4.39867675e-02,\n",
      "         3.02529763e-02],\n",
      "       [ 7.84117430e-02, -8.68821368e-02,  3.77271473e-02,\n",
      "        -2.46688798e-02, -1.19762987e-01, -1.83716081e-02,\n",
      "         6.53194189e-02,  1.59102783e-01,  2.84661017e-02,\n",
      "         1.69514082e-02],\n",
      "       [ 1.49873719e-01, -2.33182698e-01,  1.29174203e-01,\n",
      "         3.85063589e-02, -9.77312028e-02, -2.16911286e-02,\n",
      "        -1.02661110e-01,  1.20439932e-01, -5.27799651e-02,\n",
      "        -1.43973231e-02],\n",
      "       [ 1.66275203e-01, -6.17752448e-02, -5.89453727e-02,\n",
      "         3.24374810e-02, -5.51749542e-02,  3.03901769e-02,\n",
      "         1.16260141e-01,  8.42447653e-02, -6.38790280e-02,\n",
      "        -1.03692207e-02],\n",
      "       [ 1.36118680e-01, -1.16787389e-01,  3.80006954e-02,\n",
      "         8.70505273e-02,  5.10789454e-04, -2.82304585e-02,\n",
      "         2.45984010e-02,  7.17180595e-02, -1.32799834e-01,\n",
      "        -8.55114982e-02],\n",
      "       [ 1.91627622e-01, -2.63935387e-01,  4.45132554e-02,\n",
      "         5.81513271e-02, -9.87120122e-02,  3.95036563e-02,\n",
      "         1.74511611e-01,  1.01226643e-01, -1.32471725e-01,\n",
      "        -9.00025815e-02],\n",
      "       [ 1.25715703e-01, -1.65888295e-01, -2.93779373e-02,\n",
      "         1.18103676e-01,  1.20232143e-02,  3.79601903e-02,\n",
      "         1.09801933e-01,  9.84949842e-02, -2.29242846e-01,\n",
      "        -1.04284897e-01],\n",
      "       [ 8.91549885e-02, -2.70614028e-01,  6.29819557e-02,\n",
      "        -7.89459795e-03, -1.02348357e-01,  5.10921739e-02,\n",
      "        -5.17442077e-03, -7.32309371e-03, -1.17085509e-01,\n",
      "         1.55961560e-02],\n",
      "       [ 2.43444324e-01, -1.52708650e-01,  7.86574334e-02,\n",
      "         4.44588959e-02, -2.38025673e-02, -3.11100893e-02,\n",
      "        -1.83127522e-02,  7.00439587e-02, -1.31154567e-01,\n",
      "        -6.37955219e-02],\n",
      "       [ 1.85826480e-01, -6.58973902e-02,  3.55517119e-03,\n",
      "         3.14786285e-03, -6.16544299e-02, -5.05571067e-03,\n",
      "         9.06574503e-02,  5.25272116e-02, -1.56728029e-01,\n",
      "        -1.99988559e-02],\n",
      "       [ 1.02722555e-01, -1.94791898e-01,  1.95781067e-02,\n",
      "         9.08551365e-03, -4.91546243e-02,  8.17024708e-03,\n",
      "         1.35994062e-01, -8.04902613e-03, -1.96649328e-01,\n",
      "        -1.27977014e-01]], dtype=float32)>\n",
      "}}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:18:21.480277: W tensorflow/core/kernels/data/cache_dataset_ops.cc:858] The calling iterator did not fully read the dataset being cached. In order to avoid unexpected truncation of the dataset, the partially cached contents of the dataset  will be discarded. This can happen if you have an input pipeline similar to `dataset.cache().take(k).repeat()`. You should use `dataset.take(k).cache().repeat()` instead.\n"
     ]
    }
   ],
   "source": [
    "another_strategy = tf.distribute.MirroredStrategy()\n",
    "with another_strategy.scope():\n",
    "  loaded = tf.saved_model.load(saved_model_path)\n",
    "  inference_func = loaded.signatures[DEFAULT_FUNCTION_KEY]\n",
    "\n",
    "  dist_predict_dataset = another_strategy.experimental_distribute_dataset(\n",
    "      predict_dataset)\n",
    "\n",
    "  # Calling the function in a distributed manner\n",
    "  for batch in dist_predict_dataset:\n",
    "    result = another_strategy.run(inference_func, args=(batch,))\n",
    "    print(result)\n",
    "    break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hWGSukoyw3fF"
   },
   "source": [
    "调用已恢复的函数只是基于已保存模型的前向传递 (`tf.keras.Model.predict`)。如果您想继续训练加载的函数，或者将加载的函数嵌入到更大的模型中，应如何操作？通常的做法是将此加载对象封装到 Keras 层以实现此目的。幸运的是，[TF Hub](https://tensorflow.google.cn/hub) 为此提供了 [`hub.KerasLayer`](https://github.com/tensorflow/hub/blob/master/tensorflow_hub/keras_layer.py)，如下所示："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:21.504149Z",
     "iopub.status.busy": "2023-11-07T23:18:21.503429Z",
     "iopub.status.idle": "2023-11-07T23:18:29.966497Z",
     "shell.execute_reply": "2023-11-07T23:18:29.965715Z"
    },
    "id": "clfk3hQoyKu6"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-11-07 23:18:22.447273: W tensorflow/core/grappler/optimizers/data/auto_shard.cc:553] The `assert_cardinality` transformation is currently not handled by the auto-shard rewrite and will be removed.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Collective all_reduce tensors: 6 all_reduces, num_devices = 4, group_size = 4, implementation = CommunicationImplementation.NCCL, num_packs = 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 12:20 - loss: 2.2659 - sparse_categorical_accuracy: 0.1875"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "  8/235 [>.............................] - ETA: 1s - loss: 1.8580 - sparse_categorical_accuracy: 0.4658   "
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 16/235 [=>............................] - ETA: 1s - loss: 1.4582 - sparse_categorical_accuracy: 0.6265"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 24/235 [==>...........................] - ETA: 1s - loss: 1.1840 - sparse_categorical_accuracy: 0.6973"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 32/235 [===>..........................] - ETA: 1s - loss: 1.0027 - sparse_categorical_accuracy: 0.7411"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 39/235 [===>..........................] - ETA: 1s - loss: 0.8938 - sparse_categorical_accuracy: 0.7672"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 46/235 [====>.........................] - ETA: 1s - loss: 0.8114 - sparse_categorical_accuracy: 0.7873"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 54/235 [=====>........................] - ETA: 1s - loss: 0.7371 - sparse_categorical_accuracy: 0.8056"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 62/235 [======>.......................] - ETA: 1s - loss: 0.6820 - sparse_categorical_accuracy: 0.8196"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 70/235 [=======>......................] - ETA: 1s - loss: 0.6348 - sparse_categorical_accuracy: 0.8304"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 77/235 [========>.....................] - ETA: 1s - loss: 0.6028 - sparse_categorical_accuracy: 0.8385"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 85/235 [=========>....................] - ETA: 1s - loss: 0.5692 - sparse_categorical_accuracy: 0.8466"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 93/235 [==========>...................] - ETA: 1s - loss: 0.5393 - sparse_categorical_accuracy: 0.8546"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "100/235 [===========>..................] - ETA: 0s - loss: 0.5189 - sparse_categorical_accuracy: 0.8592"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "108/235 [============>.................] - ETA: 0s - loss: 0.5000 - sparse_categorical_accuracy: 0.8641"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "115/235 [=============>................] - ETA: 0s - loss: 0.4840 - sparse_categorical_accuracy: 0.8682"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "122/235 [==============>...............] - ETA: 0s - loss: 0.4670 - sparse_categorical_accuracy: 0.8726"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "129/235 [===============>..............] - ETA: 0s - loss: 0.4520 - sparse_categorical_accuracy: 0.8765"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "137/235 [================>.............] - ETA: 0s - loss: 0.4369 - sparse_categorical_accuracy: 0.8805"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "144/235 [=================>............] - ETA: 0s - loss: 0.4252 - sparse_categorical_accuracy: 0.8838"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "151/235 [==================>...........] - ETA: 0s - loss: 0.4145 - sparse_categorical_accuracy: 0.8866"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "158/235 [===================>..........] - ETA: 0s - loss: 0.4048 - sparse_categorical_accuracy: 0.8891"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "165/235 [====================>.........] - ETA: 0s - loss: 0.3957 - sparse_categorical_accuracy: 0.8912"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "172/235 [====================>.........] - ETA: 0s - loss: 0.3866 - sparse_categorical_accuracy: 0.8937"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "179/235 [=====================>........] - ETA: 0s - loss: 0.3782 - sparse_categorical_accuracy: 0.8959"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "186/235 [======================>.......] - ETA: 0s - loss: 0.3699 - sparse_categorical_accuracy: 0.8982"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "193/235 [=======================>......] - ETA: 0s - loss: 0.3620 - sparse_categorical_accuracy: 0.9002"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "200/235 [========================>.....] - ETA: 0s - loss: 0.3543 - sparse_categorical_accuracy: 0.9023"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "207/235 [=========================>....] - ETA: 0s - loss: 0.3492 - sparse_categorical_accuracy: 0.9037"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "214/235 [==========================>...] - ETA: 0s - loss: 0.3429 - sparse_categorical_accuracy: 0.9054"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "221/235 [===========================>..] - ETA: 0s - loss: 0.3357 - sparse_categorical_accuracy: 0.9074"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "228/235 [============================>.] - ETA: 0s - loss: 0.3296 - sparse_categorical_accuracy: 0.9091"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - ETA: 0s - loss: 0.3242 - sparse_categorical_accuracy: 0.9105"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 5s 7ms/step - loss: 0.3242 - sparse_categorical_accuracy: 0.9105\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 2/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "  1/235 [..............................] - ETA: 9s - loss: 0.0917 - sparse_categorical_accuracy: 0.9805"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "  8/235 [>.............................] - ETA: 1s - loss: 0.1196 - sparse_categorical_accuracy: 0.9658"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 15/235 [>.............................] - ETA: 1s - loss: 0.1244 - sparse_categorical_accuracy: 0.9654"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 22/235 [=>............................] - ETA: 1s - loss: 0.1203 - sparse_categorical_accuracy: 0.9664"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 29/235 [==>...........................] - ETA: 1s - loss: 0.1248 - sparse_categorical_accuracy: 0.9654"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 36/235 [===>..........................] - ETA: 1s - loss: 0.1237 - sparse_categorical_accuracy: 0.9659"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 43/235 [====>.........................] - ETA: 1s - loss: 0.1209 - sparse_categorical_accuracy: 0.9666"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 51/235 [=====>........................] - ETA: 1s - loss: 0.1179 - sparse_categorical_accuracy: 0.9678"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 58/235 [======>.......................] - ETA: 1s - loss: 0.1171 - sparse_categorical_accuracy: 0.9677"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 65/235 [=======>......................] - ETA: 1s - loss: 0.1151 - sparse_categorical_accuracy: 0.9684"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 73/235 [========>.....................] - ETA: 1s - loss: 0.1123 - sparse_categorical_accuracy: 0.9697"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 81/235 [=========>....................] - ETA: 1s - loss: 0.1115 - sparse_categorical_accuracy: 0.9694"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 88/235 [==========>...................] - ETA: 1s - loss: 0.1118 - sparse_categorical_accuracy: 0.9689"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      " 95/235 [===========>..................] - ETA: 1s - loss: 0.1107 - sparse_categorical_accuracy: 0.9688"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "102/235 [============>.................] - ETA: 0s - loss: 0.1104 - sparse_categorical_accuracy: 0.9689"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "109/235 [============>.................] - ETA: 0s - loss: 0.1095 - sparse_categorical_accuracy: 0.9694"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "116/235 [=============>................] - ETA: 0s - loss: 0.1084 - sparse_categorical_accuracy: 0.9698"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "123/235 [==============>...............] - ETA: 0s - loss: 0.1081 - sparse_categorical_accuracy: 0.9699"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "130/235 [===============>..............] - ETA: 0s - loss: 0.1071 - sparse_categorical_accuracy: 0.9700"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "137/235 [================>.............] - ETA: 0s - loss: 0.1063 - sparse_categorical_accuracy: 0.9702"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "144/235 [=================>............] - ETA: 0s - loss: 0.1056 - sparse_categorical_accuracy: 0.9705"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "151/235 [==================>...........] - ETA: 0s - loss: 0.1056 - sparse_categorical_accuracy: 0.9706"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "158/235 [===================>..........] - ETA: 0s - loss: 0.1048 - sparse_categorical_accuracy: 0.9708"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "166/235 [====================>.........] - ETA: 0s - loss: 0.1049 - sparse_categorical_accuracy: 0.9709"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "173/235 [=====================>........] - ETA: 0s - loss: 0.1041 - sparse_categorical_accuracy: 0.9712"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "180/235 [=====================>........] - ETA: 0s - loss: 0.1030 - sparse_categorical_accuracy: 0.9713"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "187/235 [======================>.......] - ETA: 0s - loss: 0.1032 - sparse_categorical_accuracy: 0.9712"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "194/235 [=======================>......] - ETA: 0s - loss: 0.1025 - sparse_categorical_accuracy: 0.9713"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "201/235 [========================>.....] - ETA: 0s - loss: 0.1023 - sparse_categorical_accuracy: 0.9714"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "208/235 [=========================>....] - ETA: 0s - loss: 0.1019 - sparse_categorical_accuracy: 0.9715"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "215/235 [==========================>...] - ETA: 0s - loss: 0.1009 - sparse_categorical_accuracy: 0.9717"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "222/235 [===========================>..] - ETA: 0s - loss: 0.1002 - sparse_categorical_accuracy: 0.9719"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "230/235 [============================>.] - ETA: 0s - loss: 0.0994 - sparse_categorical_accuracy: 0.9722"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "235/235 [==============================] - 2s 7ms/step - loss: 0.0989 - sparse_categorical_accuracy: 0.9723\n"
     ]
    }
   ],
   "source": [
    "import tensorflow_hub as hub\n",
    "\n",
    "def build_model(loaded):\n",
    "  x = tf.keras.layers.Input(shape=(28, 28, 1), name='input_x')\n",
    "  # Wrap what's loaded to a KerasLayer\n",
    "  keras_layer = hub.KerasLayer(loaded, trainable=True)(x)\n",
    "  model = tf.keras.Model(x, keras_layer)\n",
    "  return model\n",
    "\n",
    "another_strategy = tf.distribute.MirroredStrategy()\n",
    "with another_strategy.scope():\n",
    "  loaded = tf.saved_model.load(saved_model_path)\n",
    "  model = build_model(loaded)\n",
    "\n",
    "  model.compile(loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n",
    "                optimizer=tf.keras.optimizers.Adam(),\n",
    "                metrics=[tf.metrics.SparseCategoricalAccuracy()])\n",
    "  model.fit(train_dataset, epochs=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "Oe1z_OtSJlu2"
   },
   "source": [
    "在上面的示例中，TensorFlow Hub 的 `hub.KerasLayer` 可将从 `tf.saved_model.load` 加载回的结果封装到可用于构建其他模型的 Keras 层。这对于迁移学习非常实用。 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "KFDOZpK5Wa3W"
   },
   "source": [
    "### 我应使用哪种 API？"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GC6GQ9HDLxD6"
   },
   "source": [
    "对于保存，如果您使用的是 Keras 模型，请使用 Keras `Model.save` API，除非您需要低级 API 允许的额外控制。如果您保存的不是 Keras 模型，那么您只能选择使用较低级的 API `tf.saved_model.save`。\n",
    "\n",
    "对于加载，您的 API 选择取决于您要从加载 API 中获得什么。如果您无法（或不想）获取 Keras 模型，请使用 `tf.saved_model.load`。否则，请使用 `tf.keras.models.load_model`。请注意，只有保存 Keras 模型后，才能恢复 Keras 模型。\n",
    "\n",
    "可以搭配使用 API。您可以使用 `model.save` 保存 Keras 模型，并使用低级 API `tf.saved_model.load` 加载非 Keras 模型。 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:29.971387Z",
     "iopub.status.busy": "2023-11-07T23:18:29.970654Z",
     "iopub.status.idle": "2023-11-07T23:18:30.692867Z",
     "shell.execute_reply": "2023-11-07T23:18:30.691947Z"
    },
    "id": "Ktwg2GwnXE8v"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    }
   ],
   "source": [
    "model = get_model()\n",
    "\n",
    "# Saving the model using Keras `Model.save`\n",
    "model.save(saved_model_path)\n",
    "\n",
    "another_strategy = tf.distribute.MirroredStrategy()\n",
    "# Loading the model using the lower-level API\n",
    "with another_strategy.scope():\n",
    "  loaded = tf.saved_model.load(saved_model_path)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "0Z7lSj8nZiW5"
   },
   "source": [
    "### 从本地设备保存/加载"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "NVAjWcosZodw"
   },
   "source": [
    "在远程设备上训练的过程中从本地 I/O 设备保存和加载时（例如，使用 Cloud TPU 时），必须使用 `tf.saved_model.SaveOptions` 和 `tf.saved_model.LoadOptions` 中的选项 `experimental_io_device` 将 I/O 设备设置为 `localhost`。例如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:30.698056Z",
     "iopub.status.busy": "2023-11-07T23:18:30.697243Z",
     "iopub.status.idle": "2023-11-07T23:18:31.580884Z",
     "shell.execute_reply": "2023-11-07T23:18:31.579989Z"
    },
    "id": "jFcuzsI94bNA"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3')\n"
     ]
    }
   ],
   "source": [
    "model = get_model()\n",
    "\n",
    "# Saving the model to a path on localhost.\n",
    "saved_model_path = '/tmp/tf_save'\n",
    "save_options = tf.saved_model.SaveOptions(experimental_io_device='/job:localhost')\n",
    "model.save(saved_model_path, options=save_options)\n",
    "\n",
    "# Loading the model from a path on localhost.\n",
    "another_strategy = tf.distribute.MirroredStrategy()\n",
    "with another_strategy.scope():\n",
    "  load_options = tf.saved_model.LoadOptions(experimental_io_device='/job:localhost')\n",
    "  loaded = tf.keras.models.load_model(saved_model_path, options=load_options)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "hJTWOnC9iuA3"
   },
   "source": [
    "### 警告"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "2cCSZrD7VCxe"
   },
   "source": [
    "一种特殊情况是当您以某种方式创建 Keras 模型，然后在训练之前保存它们。例如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:31.585913Z",
     "iopub.status.busy": "2023-11-07T23:18:31.585228Z",
     "iopub.status.idle": "2023-11-07T23:18:31.596179Z",
     "shell.execute_reply": "2023-11-07T23:18:31.595440Z"
    },
    "id": "gurSIbDFjOBc"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Skipping full serialization of Keras layer <__main__.SubclassedModel object at 0x7f797645bf10>, because it is not built.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Skipping full serialization of Keras layer <__main__.SubclassedModel object at 0x7f797645bf10>, because it is not built.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ValueError:  Model <__main__.SubclassedModel object at 0x7f797645bf10> cannot be saved either because the input shape is not available or because the forward pass of the model is not defined.To define a forward pass, please override `Model.call()`. To specify an input shape, either call `build(input_shape)` directly, or call the model on actual data using `Model()`, `Model.fit()`, or `Model.predict()`. If you have a custom training step, please make sure to invoke the forward pass in train step through `Model.__call__`, i.e. `model(inputs)`, as opposed to `model.call()`.\n"
     ]
    }
   ],
   "source": [
    "class SubclassedModel(tf.keras.Model):\n",
    "  \"\"\"Example model defined by subclassing `tf.keras.Model`.\"\"\"\n",
    "\n",
    "  output_name = 'output_layer'\n",
    "\n",
    "  def __init__(self):\n",
    "    super(SubclassedModel, self).__init__()\n",
    "    self._dense_layer = tf.keras.layers.Dense(\n",
    "        5, dtype=tf.dtypes.float32, name=self.output_name)\n",
    "\n",
    "  def call(self, inputs):\n",
    "    return self._dense_layer(inputs)\n",
    "\n",
    "my_model = SubclassedModel()\n",
    "try:\n",
    "  my_model.save(saved_model_path)\n",
    "except ValueError as e:\n",
    "  print(f'{type(e).__name__}: ', *e.args)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "D4qMyXFDSPDO"
   },
   "source": [
    "SavedModel 保存跟踪 `tf.function` 时生成的 `tf.types.experimental.ConcreteFunction` 对象（请查看[计算图和 tf.function 简介](../../guide/intro_to_graphs.ipynb)指南中的*函数何时执行跟踪？*了解更多信息）。如果您收到像这样的 `ValueError`，那是因为 `Model.save` 无法找到或创建跟踪的 `ConcreteFunction`。\n",
    "\n",
    "**小心：**您不应在一个 `ConcreteFunction` 都没有的情况下保存模型，因为如果这样做，低级 API 将生成一个没有 `ConcreteFunction` 签名的 SavedModel（[详细了解](../../guide/saved_model.ipynb) SavedModel 格式）。例如："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:31.599602Z",
     "iopub.status.busy": "2023-11-07T23:18:31.599119Z",
     "iopub.status.idle": "2023-11-07T23:18:31.657625Z",
     "shell.execute_reply": "2023-11-07T23:18:31.656887Z"
    },
    "id": "064SE47mYDj8"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Skipping full serialization of Keras layer <__main__.SubclassedModel object at 0x7f797645bf10>, because it is not built.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Skipping full serialization of Keras layer <__main__.SubclassedModel object at 0x7f797645bf10>, because it is not built.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Skipping full serialization of Keras layer <keras.src.layers.core.dense.Dense object at 0x7f79765fdfa0>, because it is not built.\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:Skipping full serialization of Keras layer <keras.src.layers.core.dense.Dense object at 0x7f79765fdfa0>, because it is not built.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "_SignatureMap({})"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tf.saved_model.save(my_model, saved_model_path)\n",
    "x = tf.saved_model.load(saved_model_path)\n",
    "x.signatures"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "LRTxlASJX-cY"
   },
   "source": [
    "一般而言，模型的前向传递（`call` 方法）会在第一次调用模型时被自动跟踪，通常是通过 Keras `Model.fit` 方法。如果您设置了输入形状，例如通过将第一层设为 `tf.keras.layers.InputLayer` 或其他层类型，并将 `input_shape` 关键字参数传递给它，Keras [序贯](https://tensorflow.google.cn/guide/keras/sequential_model)和[函数式](https://tensorflow.google.cn/guide/keras/functional) API 也可以生成 `ConcreteFunction`。\n",
    "\n",
    "要验证您的模型是否有任何跟踪的 `ConcreteFunction`，请检查 `Model.save_spec` 是否为 `None`："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:31.660958Z",
     "iopub.status.busy": "2023-11-07T23:18:31.660704Z",
     "iopub.status.idle": "2023-11-07T23:18:31.664698Z",
     "shell.execute_reply": "2023-11-07T23:18:31.664005Z"
    },
    "id": "xAXise4eR0YJ"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(my_model.save_spec() is None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "G2G_FQrWJAO3"
   },
   "source": [
    "我们使用 `tf.keras.Model.fit` 来训练模型，可以注意到，`save_spec` 被定义并且模型保存将生效："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-11-07T23:18:31.668359Z",
     "iopub.status.busy": "2023-11-07T23:18:31.667682Z",
     "iopub.status.idle": "2023-11-07T23:18:32.902693Z",
     "shell.execute_reply": "2023-11-07T23:18:32.901850Z"
    },
    "id": "cv5LTi0zDkKS"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "1/7 [===>..........................] - ETA: 5s - loss: 13.1256"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "7/7 [==============================] - 1s 3ms/step - loss: 12.9327\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 2/2\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\r\n",
      "1/7 [===>..........................] - ETA: 0s - loss: 12.6170"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\r\n",
      "7/7 [==============================] - 0s 2ms/step - loss: 12.4291\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5, 5), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797651b7c0>, 140159649852656), {}).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5, 5), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797651b7c0>, 140159649852656), {}).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5,), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797646f370>, 140159650883888), {}).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5,), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797646f370>, 140159650883888), {}).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5, 5), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797651b7c0>, 140159649852656), {}).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5, 5), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797651b7c0>, 140159649852656), {}).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5,), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797646f370>, 140159650883888), {}).\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Unsupported signature for serialization: ((TensorSpec(shape=(5,), dtype=tf.float32, name='gradient'), <tensorflow.python.framework.func_graph.UnknownArgument object at 0x7f797646f370>, 140159650883888), {}).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:tensorflow:Assets written to: /tmp/tf_save/assets\n"
     ]
    }
   ],
   "source": [
    "BATCH_SIZE_PER_REPLICA = 4\n",
    "BATCH_SIZE = BATCH_SIZE_PER_REPLICA * mirrored_strategy.num_replicas_in_sync\n",
    "\n",
    "dataset_size = 100\n",
    "dataset = tf.data.Dataset.from_tensors(\n",
    "    (tf.range(5, dtype=tf.float32), tf.range(5, dtype=tf.float32))\n",
    "    ).repeat(dataset_size).batch(BATCH_SIZE)\n",
    "\n",
    "my_model.compile(optimizer='adam', loss='mean_squared_error')\n",
    "my_model.fit(dataset, epochs=2)\n",
    "\n",
    "print(my_model.save_spec() is None)\n",
    "my_model.save(saved_model_path)"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "save_and_load.ipynb",
   "toc_visible": true
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
